MapsV2 how to fake a click of the myLocation button
android, android-maps-v2
Solution
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
Problem
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?