javascript - 使用地点库搜索 Google map V3 上的现有点

标签 javascript google-maps-api-3 google-maps-markers

好吧,自从我第一次发布此内容以来,我未能正确解释我想要做什么,这是我的第二次尝试。

在我的网站上,我实现了 Google Maps V3 Javascript。创建一组预定义的点(从 CMS 内)并通过包含所需信息的数组推送到 map 。我的客户想知道的是,该站点的用户是否可以执行搜索以从该数组中查找现有点。我本以为这将涉及使用 Places 库,但这会返回来自 google 的所有有效结果,而不是来自 CMS 中创建的自定义点数组。

$('#points-search').submit(function(){
    geocoder = new gm.Geocoder();

    var searchAddress = $(this).children('input[type="text"]').val();
    var searchPoints = [];

    if (geocoder){
        geocoder.geocode({'address' : searchAddress}, function(results, status){
            if (status == gm.GeocoderStatus.OK){
                $.each(results, function(i, result){
                    searchPoints.push({"lat" : result.geometry.location.Xa, "lng" : result.geometry.location.Ya});
                });
            } else {
                                    alert('nothing found!')
            }
        });
    }

    return false;
});

当然,该代码还没有完成。从理论上讲,我想做的是,如果我搜索“4777 Avenue Pierre-de Coubertin”,它会在我的 $points 数组中找到正确的点,而不是找到蒙特利尔的现有地址和所有其他点具有该地址的世界。

lat: 45.5
lng: -73.553459
location: "2 Rue de la Commune Ouest, <br />Montreal, QC H2Y 2E2, Canada"
name: "Montreal Science Centre"
pointType: "Community"
url: "/points/item/montreal-science-centre"

lat: 45.514229
lng: -73.531342
location: "4777 Avenue Pierre-de Coubertin<br />Montreal, QC H1V 1B3, Canada"
name: "Montreal Biodome"
pointType: "Curated"
url: "/points/item/montreal-biodome"

我希望这能更清楚地描述我正在尝试做的事情。非常感谢。

最佳答案

What my client is wondering is if the users of this site can execute a search to find an existing point from this array.

答案是肯定的。搜索涉及哪些标准?信息窗口中的数据?最近点?您是否有可以更有效地进行搜索的数据库?

Theoretically what I'd like to do is, say, if I search for "4777 Avenue Pierre-de Coubertin", it would find the proper point in my $points array instead of finding that existing address in Montreal AND all the other points in the world with that address.

你有选择:

  1. 在信息窗口中的文本中搜索该字符串(或在对象的属性中搜索该地址,您可能需要制作一个不带 HTML 格式的版本以使搜索更容易)
  2. 对输入地址进行地理编码并找到标记数组中最近的点(假设结果位于您感兴趣的区域内)。
  3. 其他内容或以上内容的组合。

关于javascript - 使用地点库搜索 Google map V3 上的现有点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12978113/

相关文章:

php - 如何将亚马逊愿望 list 添加到我的网站? (PHP, jquery, CSS)

javascript - 替换两个字符串之间的多行文本

jquery - 是否可以替换 map 标记图像?

javascript - 除了 3 维数组之外,还有更好的方法来管理基于网格的游戏吗?

javascript - 单击子项时 Jquery 父类事件触发

javascript - 未捕获的类型错误 : Cannot read property '__e3_' of null

javascript - 谷歌地图 div 区域中仅显示带有缩放控制的白色

google-maps - 如果我知道 GPS 的中心位置和左上角位置,如何获得矩形的纬度和经度?

javascript - Google Maps JavaScript API V3 - Geocoder API 不返回地名

javascript - Google Maps API,在不使用坐标的情况下在国家/地区放置标记