我怎样才能在Android中的谷歌地图V2可见的标记? [英] How can I get the visible markers in Google Maps v2 in Android?
问题描述
在谷歌地图V2为Android,我怎么能得到明显的标志?我知道我可以使用投影和消除点< 0和要点>的屏幕尺寸。但我不希望由一个二选一,也可以是太慢了,如果我有很多标记。有没有简单的方法?或者一些现成的,现成的解决方案?如果有,是哪一个?
In Google Maps v2 for Android, how can I get the visible markers? I know I can use Projection and eliminate points < 0 and points > screen size. But I do not wish to check one by one, it can be too slow if I have a lot of markers. Is there any easy way? Or some off-the-shelf solution? If yes, which one?
推荐答案
好吧,下面是code之前,我已经使用,以确定哪些用户可以看到,然后只绘制可见的标记。
我想你也许能使其适应你的目的。
Ok, the following is the code the I have used before to determine what the user can see and then only draw the markers that are visible. I think you might be able to adapt it to your purpose.
获取地图的当前矩形视窗(注:必须在主线程上运行)
get the current rectangle "viewport" of the map (note:must be run on the main thread)
this.mLatLngBounds = this.mMap.getProjection().getVisibleRegion().latLngBounds;
2点(左上和右下)进行排序,以便我们可以使用最小/最大逻辑
sort the 2 points (top-left and bottom-right) so that we can use min/max logic
double lowLat;
double lowLng;
double highLat;
double highLng;
if (this.mLatLngBounds.northeast.latitude < this.mLatLngBounds.southwest.latitude)
{
lowLat = this.mLatLngBounds.northeast.latitude;
highLat = this.mLatLngBounds.southwest.latitude;
}
else
{
highLat = this.mLatLngBounds.northeast.latitude;
lowLat = this.mLatLngBounds.southwest.latitude;
}
if (this.mLatLngBounds.northeast.longitude < this.mLatLngBounds.southwest.longitude)
{
lowLng = this.mLatLngBounds.northeast.longitude;
highLng = this.mLatLngBounds.southwest.longitude;
}
else
{
highLng = this.mLatLngBounds.northeast.longitude;
lowLng = this.mLatLngBounds.southwest.longitude;
}
然后在我的情况,我在一个数据库这个数据,所以我可以使用> =和&lt; =只提取我想要的销
then in my case I had this data in a db, so i could use >= and <= to extract only the pins i wanted
这篇关于我怎样才能在Android中的谷歌地图V2可见的标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!