Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get center of map for v2 android maps?

In Google Maps for Android v1, MapView had a convenience method: getMapCenter(). Now I cannot figure out how to get map center with v2 of this api. I have perused the API documentation, but there is no mention of such a feature. Please advise.

Thanks, Igor

like image 766
IgorGanapolsky Avatar asked Dec 16 '12 18:12

IgorGanapolsky


People also ask

What is MAP padding?

It takes pixels as an integer value to pad the left, top, right, and bottom edges. It would be called as follows: map.setPadding(400, 100, 100, 0); Copy. This means that 400 pixels are padded in the left corner and 100 pixels are padded in the top and right corners.

How do you drag a map on Android?

Long press the marker to enable dragging. When you take your finger off the screen, the marker will remain in that position. Markers are not draggable by default. You must explicitly set the marker to be draggable either with MarkerOptions.


1 Answers

I had the same problem. It seems you can get the center this way:

mMap.getCameraPosition().target 

where mMap is the GoogleMap instance from your activity. This will return a LatLng object which basically represents the center of the map.

Note that the GeoPoint class is not available anymore.

According to http://developer.android.com/reference/com/google/android/gms/maps/model/CameraPosition.html

target is "The location that the camera is pointing at." (I tested it with the sample code and it worked okay for me)

like image 184
Radu Comaneci Avatar answered Sep 30 '22 10:09

Radu Comaneci