开发者

Claculate the area currently displayed by the Android MapView [duplicate]

开发者 https://www.devze.com 2023-03-08 21:07 出处:网络
This question already has answers here: Closed 10 years ago. Possible开发者_StackOverflow社区 Duplicate:
This question already has answers here: Closed 10 years ago.

Possible开发者_StackOverflow社区 Duplicate:

How can I determine if a geopoint is displayed in currently viewable area?

Is there any efficient way by which I can know how much area (in terms of Geo points) my map view is displaying with respect to the current zoom level?

Like in the geometry, we know that the upper left might start from (0,0) and the lower right might end at (320,480), is there some way by which I can know that the current upper left GeoPoint is, say (76.3213,54.5678) and the lower right is (112.2345, 132.4567) ?

Ultimately, I would want to query a database to send me information that is related to GeoLocations greater than the starting point and lesser than the ending point.


There are a couple ways to do this:

One, use MapView.getProjection(), which allows you to convert between screen coordinates and GeoPoints.

Two, use a combination of MapView.getMapCenter(), MapView.getLatitudeSpan(), and MapView.getLongitudeSpan() and do a little bit of math. The first option sounds better in your case, but your mileage may vary.

Either way, the MapView doc is located in full here


Using

 mapview.getTop(), mapview.getBottom(), mapview.getLeft(), mapview.getRight() 

to get position of edge of mapview. Then using

mapView.getProjection().fromPixels(x, y);

to get coordinates. When you got that corrdinates, store it in database, and query them is simple.

0

精彩评论

暂无评论...
验证码 换一张
取 消