MapsV2 how to fake a click of the myLocation button
Asked Answered
S

1

6

In MapsV2, I would like to programmatically perform a click of the myLocation button that appears on the top right of the map.

In previous versions of MapsV2, I could get a handle on the button by traversing the view hierarchy and then say myButton.performClick() (and also if I wanted could reposition the button on the map). But in the latest release this has stopped working so I think Google have deliberately disabled this potential.

How else can I center the map on the current location from code, as if the user had pressed the button?

Squalene answered 16/12, 2013 at 18:0 Comment(0)
F
7

just use

map.getMyLocation()

which returns you the location of the blue dot then just change the camera to that location

CameraPosition position = new CameraPosition.Builder()
   .target(new LatLng(location.getLatitude(),location.getLongitude()))
   .zoom(zoom).build();

map.animateCamera(CameraUpdateFactory.newCameraPosition(position));

there is also a OnMyLocationButtonClickListener if you want to listen for the my location button click

Fisherman answered 16/12, 2013 at 18:5 Comment(1)

© 2022 - 2024 — McMap. All rights reserved.