My location and marker have different locations

Why does my location and marker have different locations? Before the addition of the marker I click on a floating button, and when I click on it, I call getLatitude, and getLongitudefrom LocationManager. This is similar to when the map is ready and moving the camera, so I think the marker and mylocation should be the same:

enter image description here

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 install MyLocationListener:

locationListener = new MyLocationListeners();
locationManager.requestLocationUpdates(
        LocationManager.GPS_PROVIDER,
        5000,
        10,
        locationListener
);
+4
source share
1 answer

My location level uses its own location provider, which is not a Fused Location Provider provider or location manager. From the documentation :

GoogleMap , , .

, My location, Fused Location ( , GPS ,...).

GoogleMap.setLocationSource.

0

Source: https://habr.com/ru/post/1648010/


All Articles