简体   繁体   中英

Google Maps trace my location

I have GoogleMaps V2 in android.
How can I center the map at my location and trace my location automatically, that if I moved, the map will set my new location in the center of the map. And how can I make that the circle of the accuracy will be in full size (all over the control)?

To track current location use LocationClient . More info here: http://developer.android.com/training/location/receive-location-updates.html

After you receive Location update from it, you may want to call GoogleMap.animateCamera to center on it.

To zoom on the circle, you need to know its size. Location.getAccuracy will tell you that. Then you may use this ugly function of mine to calculate LatLngBounds from center point and radius in meters, which can be put into animateCamera for your desired result.

let's assume that the declared variable is GoogleMap mMap;

add these to your mMap :

mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
mMap.setMyLocationEnabled(true);

after that, there will be a button at the top right position of your map, similar with the ones inside the google Maps application, press it, and your movement will be followed.

what do you mean with full size accuracy circle? the smaller the circle, the better your location accuracy.

Regards,

Reid

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM