get bounds of a location in google map android v2

被刻印的时光 ゝ 提交于 2019-12-05 10:33:17

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/16504639/get-bounds-of-a-location-in-google-map-android-v2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!