2011-03-28 88 views
2

我已阅读this question,但我有一些遗憾适用于我的情况,因为我有很多标记(atm〜5000,每天都在增长)。如何使用Google Maps API v.3将最近的标记找到可见地图区域中的已知点?

在我的应用程序中,用户将他的标记(让它称为标记A)点击地图或通过地址进行地理编码;我必须知道在标记A的特定半径内是否有标记。

正如我所说的,我无法遍历所有标记,它可能会杀死用户浏览器,并且如果可能的话,我很乐意避免ajax请求搜索到我的数据库。

其实我通过MarkerManager

插入地图上的标记是否有办法仅在地图的可视区域内的标记之间的搜索?

回答

1

很多很多的研究后,我迭代结束解决方案(demo here)。

为了减少迭代的项目数量,我在状态基础上划分(目前已被确认),也许将来我可以添加更多的分割。

如果它可以是有用的给别人,我的“解决方案”意味着像磁盘阵列:

places = { 
    "it":[ 
     "Rome", 
     "Venice" 
    ], 
    "fr":[ 
     "Paris", 
     "Lyon" 
    ], 
    "es":[ 
     "Madrid", 
     "Barcelona", 
     "Girona" 
    ] 
} 

而且谷歌的地理编码与用户标记COORDS拿到状态(“FR”,“它” )在哪里寻找地点。

0

您可以使用方法getBounds()这将检索LatLngBounds对象。通过这个对象,您可以调用方法getNorthEast(); getSouthWest(),这些方法将分别检索地图的西北和东南边界。 知道这些界限,你可以在你的应用程序执行计算 (伪代码):

if (yourPointLatitude > southWestBoundLatitude && yourPointLatitude < northWestBoundLatitude && yourPointLongitude > northWestBoundLongitude && yourPointLongitude < southEastBoundLongitude) 
{ 
    //take some action, the point is in the map bounds 
} 

注:这种情况下,只对特定的地理位置 - >只会世界的东北季度工作(为例如欧洲)。如果你想为不同的位置,用其他的逻辑if语句,就是这样......

编辑:看看这些链接的详细信息:Map LatLngBounds

+0

难道你的意思是if(yourPointLatitude> southWestBoundLatitude && yourPointLatitude southWestBoundLongitude && yourPointLongitude User24231 2013-03-14 13:55:53

相关问题