Why does my location and marker have different locations? Before adding the marker I click on the floating button and when I click that, I call getLatitude
and getLongitude
from LocationManager
. It's similar to when the is map ready and move camera so I think the marker and mylocation must be the same:
This is my code:
private class MyLocationListeners implements LocationListener {
@Override
public void onLocationChanged(Location location) {
longitude = null;
latitude = null;
longitude = String.valueOf(location.getLongitude());
Log.d(TAG, "onLocationChanged1: " + longitude);
latitude = String.valueOf(location.getLatitude());
Log.d(TAG, "onLocationChanged2: " + latitude);
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
}
Code where I set MyLocationListener
:
locationListener = new MyLocationListeners();
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
5000,
10,
locationListener
);