Skip to content Skip to sidebar Skip to footer

Why Does Map Marker Lurch Around The Map

I'm in Android Studio and I have a map fragment (com.google.android.gms.maps.SupportMapFragment) that has two markers. One is static and called Target. The other tracks my movement

Solution 1:

After seeing your other question, it looks like the non-map Activity is getting the onProviderEnabled() callback, but your map Activity is not getting it (unless the GPS radio is enabled during use of the map Activity).

Instead of only calling registerForUpdates() in the onProviderEnabled() callback, call it in onCreate() if the GPS radio is enabled, and fall-back to Network Location if GPS is disabled and Network Location is enabled.

Something like this:

    LocationManager locationManager = (LocationManager) this.getSystemService(this.LOCATION_SERVICE);
    if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        registerForUpdates();
    }
    elseif (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
    }

Another thing to note is that you should unregister from all location callbacks in the onPause() override for your Activities that request location updates, so that you don't have unnecessary battery drain caused by your app.

Solution 2:

I was using network instead of GPS.

Changed

 locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);

To

 locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);

It now tracks my movements smoothly. Thanks to Daniel Nugent for pointing this out to me an another post.

Greg

Post a Comment for "Why Does Map Marker Lurch Around The Map"