Google地图在地图上获得所有标记的10个最接近的点 [英] Google Map get 10 closest Points of all Markers on a Map

查看:82
本文介绍了Google地图在地图上获得所有标记的10个最接近的点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从谷歌地图的中心获得距离中心最近的10个标记,并在Javascript中根据距离对中心进行排序。所以我们可以说我有一个Javascript数组中的100个标记 - 我想在html无序列表中显示更多关于10个闭包的信息。
我为api版本2找到了一个类似的例子(版本2中的例子),但谷歌地图API版本3没有。

I try to get the 10 closest Markers from the center of the google map and sort them based of the center by distance in Javascript. So lets say i have 100 Markers in a Javascript array - i would like to display more informations about the 10 closests in a html unordered list. I found a similar example for api version 2 (example in version 2), but nothing for version 3 of google map api.

推荐答案

无论发生什么事情,您需要计算所有距离。您可以使用简单的公式自行完成,也可以使用Google的几何库: http: //code.google.com/intl/pl-PL/apis/maps/documentation/javascript/geometry.html 及其函数:computeDistanceBetween()。然后将距离存储在自定义标记属性中,例如:

Whatever happens You need to calculate all distances. You can do it yourself with simple equations or use Google's geometry library: http://code.google.com/intl/pl-PL/apis/maps/documentation/javascript/geometry.html and its function: computeDistanceBetween(). Then store distance in custom marker property like e.g:

marker.distance = google.maps.geometry.spherical.computeDistanceBetween(marker.position, center.position);

并根据需要进行排序。
希望它有帮助。

and sort it anyway you want. Hope it helps.

这篇关于Google地图在地图上获得所有标记的10个最接近的点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆