好吧,自从我第一次发布此内容以来,我未能正确解释我想要做什么,这是我的第二次尝试。
在我的网站上,我实现了 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.
你有选择:
- 在信息窗口中的文本中搜索该字符串(或在对象的属性中搜索该地址,您可能需要制作一个不带 HTML 格式的版本以使搜索更容易)
- 对输入地址进行地理编码并找到标记数组中最近的点(假设结果位于您感兴趣的区域内)。
- 其他内容或以上内容的组合。
关于javascript - 使用地点库搜索 Google map V3 上的现有点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12978113/