Luch Filip
Luch Filip

Reputation: 1133

Android Update Current Location

So here is my method for getting the user saved location and then move camera to that location:

     private void updatePlaces(){

    locMan = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    Location lastLoc = locMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

    double lat = lastLoc.getLatitude();
    double lng = lastLoc.getLongitude();

    LatLng lastLatLng = new LatLng(lat, lng);

    if(userMarker!=null) userMarker.remove();

    userMarker = theMap.addMarker(new MarkerOptions()
    .position(lastLatLng)
    .title("You are here")
    .icon(BitmapDescriptorFactory.fromResource(userIcon))
    .snippet("Your last recorded location"));
    theMap.animateCamera(CameraUpdateFactory.newLatLng(lastLatLng), 3000, null);
    }

How can i modify this code in order to get the new position only once, compare and then get camera to it?

Thank you in advance.

Upvotes: 0

Views: 514

Answers (1)

Emil Adz
Emil Adz

Reputation: 41099

I don't understand you question, if you run the method updatePlaces() only ones it will getLastKnownLocation only once and updates the user marker only once. could you please be more explanatory on what you are trying to achieve?

Upvotes: 1

Related Questions