0

How can I zoom in and move to my current location when I click on the My Location button?

I have the following implementation for this:

 googleMap.setMyLocationEnabled(true);

This shows the button but nothing happens when I press on this. How can I move to my current location?

2 Answers2

0

Use this

googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 8.0f));
Mayank Saini
  • 3,017
  • 24
  • 25
0
 googleMap.setMyLocationEnabled(true);

Only displays your location.

Use this for the zoom to your location button:

 googleMap.getUiSettings().setMyLocationButtonEnabled(true);


Here is a pretty good tutorial.

Stephan
  • 15,704
  • 7
  • 48
  • 63
  • Where do I set this? How do I detect clicking on the my location button? – user2998771 Feb 05 '14 at 10:42
  • You don't have to detect if the button is clicked. It is done for you: http://developer.android.com/reference/com/google/android/gms/maps/UiSettings.html#setMyLocationButtonEnabled(boolean) Place it after creating your googleMap. – Stephan Feb 05 '14 at 10:49