get bounds of a location in google map android v2

2019-04-02 18:48发布

Consider I have the LatLng of location A in the map. how can I get the Latlng of B and C position on the map? I want to get the bounds of the red box.

EDIT: I want to get the bound of this box and limit the camera to that bound, so user can not change the camera and go outside this bound

enter image description here

1条回答
乱世女痞
2楼-- · 2019-04-02 19:17

The code I posted in this answer: MKCoordinateRegionMakeWithDistance equivalent in Android will get bounds for you.

Usage:

LatLngBounds bounds = boundsWithCenterAndLatLngDistance(centerPointPosition, 12000, 12000); // 12000 in meters

This answers your original question about getting bounds. You can also get point B and C from bounds easily.

Now the problem is you cannot restrict user panning with the current API. You may try to use onCameraChange to detect when you are outside and force it back, but that won't give any good user experience in my opinion.

I think you are better of moving camera to this bounds only once and giving them free hand to swipe to Africa anytime they want. In the end they will use app functionality, which is in your bounds.

查看更多
登录 后发表回答