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.

 @Override
public void onLocationChanged(Location location) {
if (myLocationListener != null) {
myLocationListener.onLocationChanged(location);

double lat = location.getLatitude();
double lon = location.getLongitude();

tvLocInfo.setText(
"lat: " + lat + "\n" +
"lon: " + lon);

LatLng latlng= new LatLng(location.getLatitude(), location.getLongitude());
myMap.animateCamera(CameraUpdateFactory.newLatLng(latlng));

}
}

Detect and animate to user location


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

thumbnail
Title: Detect and animate to user location
Rating: 100% based on 99998 ratings. 10 user reviews.
Post by

Related articles :

0 comments:

Post a Comment

My Blog List

 
Copyright © 2015. About - Web Version - Mobile Version Sitemap - Contact - Privacy