private GeoPoint getLocation ( ) { //sample data //{"timestamp": 1483742439, "iss_position": {"latitude": "-50.8416", "longitude": "-41.2701"}, "message": "success"} NetworkInfo activeNetwork = cm . getActiveNetworkInfo ( ) ; boolean isConnected = activeNetwork != null && activeNetwork . isConnectedOrConnecting ( ) ; GeoPoint pt = null ; if ( isConnected ) { try { JSONObject jsonObject = json . makeHttpRequest ( url_select ) ; JSONObject iss_position = ( JSONObject ) jsonObject . get ( "iss_position" ) ; double lat = iss_position . getDouble ( "latitude" ) ; double lon = iss_position . getDouble ( "longitude" ) ; //valid the data if ( lat <= 90d && lat >= - 90d && lon >= - 180d && lon <= 180d ) { pt = new GeoPoint ( lat , lon ) ; } else Log . e ( TAG , "invalid lat,lon received" ) ; } catch ( Throwable e ) { Log . e ( TAG , "error fetching json" , e ) ; } } return pt ; }
HTTP callout to get a JSON document that represents the IIS s current location