Fel*_*ipe 2 android google-maps-android-api-2
在Google Maps v2 for Android中,如何获取可见标记?我知道我可以使用Projection并消除点<0和点>屏幕尺寸.但我不想逐一检查,如果我有很多标记,它可能会太慢.有什么简单的方法吗?还是一些现成的解决方案?如果是的话,哪一个?
Cor*_*ott 11
好的,以下是我以前使用的代码,用于确定用户可以看到的内容,然后只绘制可见的标记.我想你可能能够适应你的目的.
获取地图的当前矩形"视口"(注意:必须在主线程上运行)
this.mLatLngBounds = this.mMap.getProjection().getVisibleRegion().latLngBounds;
Run Code Online (Sandbox Code Playgroud)
对2个点(左上角和右下角)进行排序,以便我们可以使用最小/最大逻辑
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;
}
Run Code Online (Sandbox Code Playgroud)
然后在我的情况下我在db中有这些数据,所以我可以使用> =和<=来仅提取我想要的引脚
| 归档时间: |
|
| 查看次数: |
5456 次 |
| 最近记录: |