Home » » Detect and animate to user location

Detect and animate to user location

Written By MR HARI on Kamis, 24 Januari 2013 | 11.19

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.

Share this article :

0 komentar:

Posting Komentar

 
Support : Your Link | Your Link | Your Link
Copyright © 2013. Android Center - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger