obizues
obizues

Reputation: 1483

Google Maps Last Good Map Location

I am trying to keep a user within certain map boundries, so my solution is to check if the XY axis is within bounds, and if it is not, to change it back to the previous location that was within bounds.

Currently I have this functionality taking the last good location at the end of the setOnCameraChangeListener.

The problem is the listener only fires after the entire camera movement is completed.

That means that even though the user may slowly creep towards the boundary of the map, unless they stop, the last good location could be all the way on the other side of the map.

Is there a more fluid way I can get the last good location than using the listener? Maybe a listener that fires while the camera is moving instead of at the end?

Upvotes: 0

Views: 34

Answers (1)

Shane Duffy
Shane Duffy

Reputation: 1147

You should use the onLocationChanged listener. You can implement it as follows:

public class myActivity implements LocationListener {

    @Override
    public void onLocationChanged(Location loc) {
        // if (loc.getLatitide() or loc.getLongitude() is within bounds)
        //    save location as last good location
    }
}

Upvotes: 1

Related Questions