For google maps I have set option setMyLocationEnabled(true)
and it draws my location on map, but the location I get from LocationListener
is different. The marker I add from onLocationChange(Location location)
and the my-location (the blue dot) are not always in the same place.
Location updates:
@Override
public void onMapLoaded() {
try {
LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
Location getLastLocation = locationManager.getLastKnownLocation
(LocationManager.PASSIVE_PROVIDER);
try {
if (locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER)) {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2 * 1000, 5, this);
}
if (locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER)) {
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 2 * 1000, 5, this);
}
} catch (SecurityException ex) {
ex.printStackTrace();
}
} catch (NullPointerException | SecurityException ex) {
ex.printStackTrace();
}
}
@Override
public void onLocationChanged(Location location) {
LatLng objLatLng = new LatLng(location.getLatitude(), location.getLongitude());
marker = map.addMarker(new MarkerOptions().position(objLatLng));
}
So my question is how can I get the location source of the my-location layer or how to change my location update request so that the have same locations?