Thursday, January 24, 2013

Detect and animate to user location

Last exercise "Implement LocationSource and LocationListener for Google Maps Android API v2" to detect user location. We can modify onLocationChanged() method to animate to updated user location; such that the GoogleMap will always center on user location.

 public void onLocationChanged(Location location) {
  if (myLocationListener != null) {
   double lat = location.getLatitude();
   double lon = location.getLongitude();
     "lat: " + lat + "\n" +
     "lon: " + lon);
   LatLng latlng= new LatLng(location.getLatitude(), location.getLongitude());

Detect and animate to user location

The series:
A simple example using Google Maps Android API v2, step by step.


BBonDoo said...

Is there a easy method to convert LatLng() to Location() in the new Google Maps API v2 ?

Erik said...

hello BBonDoo,

Please read the post Convert between LatLng and Location.

Eli said...


Is there a way to locate users enrolled to my app? Thanks.