0

I paint the current location on a googlemap. But I am only showing half of the map (the other half is hidden under another view, but I cannot change this).

I want to move the camera to center the top half of the map in the current location, can you help me to do this? Is there a way to set the x and y of the view where I want to show the current location?

I am using Google Maps Android API v2.

1 Answers1

1

The google.maps.Map class has a method called setCenter which takes in a google.maps.LatLng as its only parameter. This method centers the map on the given LatLng. Using some clever code, you could first use the getCenter() method on the map to determine the true center of the map, then average the latitude of that LatLng with the latitude of the top of the viewport. This will give you the latitude of your new center. The longitude of your new center will remain the same. Set the map to this new coordinate pair and your problem is solved.

Happy coding!

  • RouteMapper
RouteMapper
  • 2,484
  • 1
  • 26
  • 45
  • I cannot find that method in Android's googlemap [link](https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/GoogleMap). Can you tell me where to find it? – user1448668 Apr 29 '13 at 12:58
  • Refer to this post for a full explanation: http://stackoverflow.com/questions/13904505/how-to-get-center-of-map-for-v2-android-maps – RouteMapper Apr 30 '13 at 15:42