/** * Returns the distance between the two locations in meters. * Adapted from: http://stackoverflow.com/questions/837872/calculate-distance-in-meters-when-you-know-longitude-and-latitude-in-java */ private static float distanceBetween(Location location1, Location location2) { double earthRadius = 3958.75; double latDifference = Math.toRadians(location2.getLatitude() - location1.getLatitude()); double lonDifference = Math.toRadians(location2.getLongitude() - location1.getLongitude()); double a = Math.sin(latDifference/2) * Math.sin(latDifference/2) + Math.cos(Math.toRadians(location1.getLatitude())) * Math.cos(Math.toRadians(location2.getLatitude())) * Math.sin(lonDifference/2) * Math.sin(lonDifference/2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); double dist = Math.abs(earthRadius * c); int meterConversion = 1609; return (float) (dist * meterConversion); }
@Override public void onLocationChanged(Location location) { XLog.d("Location: %f/%f", location.getLatitude(), location.getLongitude()); }
@TargetApi(Build.VERSION_CODES.KITKAT) public void onLocationChanged(Location location) { StringBuilder buf=new StringBuilder("whereami("); buf.append(String.valueOf(location.getLatitude())); buf.append(","); buf.append(String.valueOf(location.getLongitude())); buf.append(")"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { browser.evaluateJavascript(buf.toString(), null); } else { browser.loadUrl("javascript:" + buf.toString()); } }
@JavascriptInterface public String getLocation() throws JSONException { Location loc=myLocationManager.getLastKnownLocation(PROVIDER); if (loc == null) { return(null); } JSONObject json=new JSONObject(); json.put("lat", loc.getLatitude()); json.put("lon", loc.getLongitude()); return(json.toString()); } }
@JavascriptInterface public String getLocation() throws JSONException { Location loc=myLocationManager.getLastKnownLocation(PROVIDER); if (loc==null) { return(null); } JSONObject json=new JSONObject(); json.put("lat", loc.getLatitude()); json.put("lon", loc.getLongitude()); return(json.toString()); } }
private LatLng locationToLatLng(Location location) { return new LatLng(location.getLatitude(), location.getLongitude()); }
public static Point markLocation(MapView mMapView, Location location, GraphicsOverlay gLayerPos, PictureMarkerSymbol mMarkerSymbol, boolean isGPS, boolean isCenter) { Gps gps = getGps(location.getLongitude(), location.getLatitude(), isGPS); return markLocation(mMapView, gps, gLayerPos, mMarkerSymbol, isCenter); }
private void fetchForecast(Location location) { double roundedLat=(double)Math.round(location.getLatitude()*10000d)/10000d; double roundedLon=(double)Math.round(location.getLongitude()*10000d)/10000d; nws.getForecast(roundedLat, roundedLon) .enqueue(new Callback<WeatherResponse>() { @Override public void onResponse(Call<WeatherResponse> call, Response<WeatherResponse> response) { if (response.code()==200) { adapter=new ForecastAdapter(response.body().properties.periods); setListAdapter(adapter); } else { Toast.makeText(getActivity(), R.string.msg_nws, Toast.LENGTH_LONG).show(); } } @Override public void onFailure(Call<WeatherResponse> call, Throwable t) { Toast.makeText(getActivity(), t.getMessage(), Toast.LENGTH_LONG).show(); Log.e(getClass().getSimpleName(), "Exception from Retrofit request to National Weather Service", t); } }); }
void fetchForecast(Location location) { double roundedLat=(double)Math.round(location.getLatitude()*10000d)/10000d; double roundedLon=(double)Math.round(location.getLongitude()*10000d)/10000d; nws.getForecast(roundedLat, roundedLon) .enqueue(new Callback<WeatherResponse>() { @Override public void onResponse(Call<WeatherResponse> call, Response<WeatherResponse> response) { if (response.code()==200) { adapter=new ForecastAdapter(response.body().properties.periods); setListAdapter(adapter); } else { Toast.makeText(getActivity(), R.string.msg_nws, Toast.LENGTH_LONG).show(); } } @Override public void onFailure(Call<WeatherResponse> call, Throwable t) { Toast.makeText(getActivity(), t.getMessage(), Toast.LENGTH_LONG).show(); Log.e(getClass().getSimpleName(), "Exception from Retrofit request to National Weather Service", t); } }); }
void fetchForecast(Location location) { double roundedLat=(double)Math.round(location.getLatitude()*10000d)/10000d; double roundedLon=(double)Math.round(location.getLongitude()*10000d)/10000d; call=nws.getForecast(roundedLat, roundedLon); call.enqueue(new Callback<WeatherResponse>() { @Override public void onResponse(Call<WeatherResponse> call, Response<WeatherResponse> response) { if (response.code()==200) { adapter=new ForecastAdapter(response.body().properties.periods); setListAdapter(adapter); } else { Toast.makeText(getActivity(), R.string.msg_nws, Toast.LENGTH_LONG).show(); } } @Override public void onFailure(Call<WeatherResponse> call, Throwable t) { Toast.makeText(getActivity(), t.getMessage(), Toast.LENGTH_LONG).show(); Log.e(getClass().getSimpleName(), "Exception from Retrofit request to National Weather Service", t); } }); }
@Override public void onLocationChanged(Location location) { double roundedLat=(double)Math.round(location.getLatitude()*10000d)/10000d; double roundedLon=(double)Math.round(location.getLongitude()*10000d)/10000d; nws.getForecast(roundedLat, roundedLon) .enqueue(new Callback<WeatherResponse>() { @Override public void onResponse(Call<WeatherResponse> call, Response<WeatherResponse> response) { if (response.code()==200) { adapter=new ForecastAdapter(response.body().properties.periods); setListAdapter(adapter); } else { Toast.makeText(getActivity(), R.string.msg_nws, Toast.LENGTH_LONG).show(); } } @Override public void onFailure(Call<WeatherResponse> call, Throwable t) { Toast.makeText(getActivity(), t.getMessage(), Toast.LENGTH_LONG).show(); Log.e(getClass().getSimpleName(), "Exception from Retrofit request to National Weather Service", t); } }); }
@Override public void onLocationChanged(Location location) { double roundedLat=(double)Math.round(location.getLatitude()*10000d)/10000d; double roundedLon=(double)Math.round(location.getLongitude()*10000d)/10000d; nws.getForecast(roundedLat, roundedLon) .enqueue(new Callback<WeatherResponse>() { @Override public void onResponse(Call<WeatherResponse> call, Response<WeatherResponse> response) { if (response.code()==200) { adapter=new ForecastAdapter(response.body().properties.periods); setListAdapter(adapter); } else { Toast.makeText(getActivity(), R.string.msg_nws, Toast.LENGTH_LONG).show(); } } @Override public void onFailure(Call<WeatherResponse> call, Throwable t) { Toast.makeText(getActivity(), t.getMessage(), Toast.LENGTH_LONG).show(); Log.e(getClass().getSimpleName(), "Exception from Retrofit request to National Weather Service", t); } }); }
public LocationAssert hasLatitude(double latitude) { isNotNull(); double actualLatitude = actual.getLatitude(); assertThat(actualLatitude) // .overridingErrorMessage("Expected latitude <%s> but was <%s>.", latitude, actualLatitude) // .isEqualTo(latitude); return this; }
@Override public void onReceive(Context context, Intent intent) { location = NovoCompass.getLocator().getLocation(); magField = new GeomagneticField((float) location.getLatitude(), (float) location.getLongitude(), (float) location.getAltitude(), System.currentTimeMillis()); } };
@Override public void onLocationChanged(Location location) { if (mapLocationListener != null) { mapLocationListener.onLocationChanged(location); LatLng latlng= new LatLng(location.getLatitude(), location.getLongitude()); CameraUpdate cu=CameraUpdateFactory.newLatLng(latlng); map.animateCamera(cu); } }
Locale.US, "%f,%f", location.getLatitude(), location.getLongitude())); parameters.putInt("distance", radiusInMeters);
Locale.US, "%f,%f", location.getLatitude(), location.getLongitude()));
@Override public void onDataChange(DataSnapshot dataSnapshot) { if (location==null)return; databaseReference.child("Users"). child(GlobalInfo.PhoneNumber).child("Location").child("lat") .setValue( location.getLatitude()); databaseReference.child("Users"). child(GlobalInfo.PhoneNumber).child("Location").child("lag") .setValue( location.getLongitude()); DateFormat df= new SimpleDateFormat("yyyy/MM/dd HH:MM:ss"); Date date= new Date(); databaseReference.child("Users"). child(GlobalInfo.PhoneNumber).child("Location"). child("LastOnlineDate") .setValue(df.format(date).toString()); }
private Location copyOf(Location location) { if (location == null) return null; Location copy = new Location(location); copy.setAccuracy(location.getAccuracy()); copy.setAltitude(location.getAltitude()); copy.setBearing(location.getBearing()); copy.setExtras(location.getExtras()); copy.setLatitude(location.getLatitude()); copy.setLongitude(location.getLongitude()); copy.setProvider(location.getProvider()); copy.setSpeed(location.getSpeed()); copy.setTime(location.getTime()); return copy; }
@Test public void simulateLocation_shouldNotNotifyListenerIfLessThanMinimumDistance() throws Exception { TestLocationListener listener = new TestLocationListener(); locationManager.requestLocationUpdates(GPS_PROVIDER, 0, 200000, listener); Location location1 = new Location(GPS_PROVIDER); location1.setLatitude(1); location1.setLongitude(2); location1.setTime(0); Location location2 = new Location(GPS_PROVIDER); location2.setLatitude(1.5); location2.setLongitude(2.5); location2.setTime(1000); shadowLocationManager.simulateLocation(location1); shadowLocationManager.simulateLocation(location2); assertThat(listener.location.getLatitude()).isEqualTo(1.0d); assertThat(listener.location.getLongitude()).isEqualTo(2.0d); }