Punto central de mapas incorrecto

My app has a title activity and several child activities including one that is predominantly a google maps screen.

I've recently added an option for the app user to choose to center the map on the users location (using the droid devices GPS or similar).

Problem is that once this has been chosen, and then un-chosen, it still centers on the correct location, then changes to their physical location within a couple of seconds.

Any ideas how can I prevent this from happening?

@Override
public void onCreate(Bundle savedInstanceState) {
    ...
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60L, (float) 100.0, onLocationChange);
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60L, (float) 100.0, onLocationChange);
    provider = locationManager.getBestProvider(criteria, false);
    location = locationManager.getLastKnownLocation(provider);

    settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    location = locationManager.getLastKnownLocation(provider);
}

public void onStop() {
    super.onStop();
    locationManager.removeUpdates(onLocationChange);
    if (timer != null) {
        timer.cancel();
    }
}

@Override
public void onRestart() {
    super.onRestart();  
    settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    ...
    location = locationManager.getLastKnownLocation(provider);
}

preguntado el 10 de marzo de 12 a las 11:03

1 Respuestas

Looks like I'm my own worst enemy.

The problem is that I was setting the location in

LocationListener onLocationChange=new LocationListener() {
    public void onLocationChanged(Location location) {
        setMapCentre(location.getLatitude(), location.getLongitude());
        map.getController().setZoom(13 + zoomModifier);

    }

The fix was simply to add some logic to test if the user wants to center and zoom to their location.

LocationListener onLocationChange=new LocationListener() {
    public void onLocationChanged(Location location) {
        if (zoomtown.equals(" zoomme")) {
            setMapCentre(location.getLatitude(), location.getLongitude());
            map.getController().setZoom(13 + zoomModifier);
        }
    }

respondido 11 mar '12, 03:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.