1

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?

pepela
  • 423
  • 5
  • 17
  • Take a look at http://stackoverflow.com/questions/38394172/android-my-location-and-marker-have-a-different-location/38395765#38395765 – antonio Nov 04 '16 at 09:03
  • I am aware that it uses build in location provider, but I want to access it or know how its configured. – pepela Nov 04 '16 at 09:06
  • It uses it's own implementation and it's not guaranteed to be the same between implementations, so as I state in that answer, the best option is to replace the default location provider for the my-location layer using the `GoogleMap.setLocationSource` method – antonio Nov 04 '16 at 09:09
  • I don't want to replace with my location source as the default one looks smoother, but I'll do it later if I cant get the default one. – pepela Nov 04 '16 at 09:12

0 Answers0