Skip to content Skip to sidebar Skip to footer

Updating User's Location

I'm having some trouble with Google Maps. I need to display user's location on the map and then update it. I'm using a default marker. However, the way my code is currently set up,

Solution 1:

Update your onLocationChanged method by this

@OverridepublicvoidonLocationChanged(Location location) {
latitude_user = location.getLatitude();
longitude_user = location.getLongitude();

if (latitude_user != null && longitude_user != null) {
    if(marker != null)
        marker.remove();
    koordinate_user = newLatLng(latitude_user, longitude_user);
    marker = supportMap.addMarker(newMarkerOptions()
            .position(koordinate_user));
}

}

Hope this is what you wanted.

Solution 2:

you can update user location onLocationchanged method....

@OverridepublicvoidonLocationChanged(Location location) {
   latitude = location.getLatitude();
   longitude = location.getLongitude();

   if (latitude != null && longitude != null) {
     if(marker != null)
       marker.remove();
       latlng = newLatLng(latitude, longitude);
        marker = supportMap.addMarker(newMarkerOptions()
        .position(latlng));
     }

    }

Post a Comment for "Updating User's Location"