gpt4 book ai didi

javascript - 如何在 google maps api 中创建带有建议的 "did you mean"链接?

转载 作者:行者123 更新时间:2023-11-30 06:06:32 26 4
gpt4 key购买 nike

我正在尝试使用 google maps api 制作一个 web 应用程序,它提供方向。现在,除非用户输入错误,否则它会给出很好的指示,它要么不显示任何内容,要么试图弄清楚并给出错误的地址。我想在无法识别地址的情况下提供“您的意思是”的功能,然后提出与您尝试输入的内容接近的建议。我在谷歌代码中找不到任何相关内容,但我想知道是否有人知道这是否可行,我该怎么做?

谢谢!

最佳答案

loadFromWayPoints() 仅当提供给它的输入映射到地球上的任何确定点时才绘制折线。您可以通过以纬度和经度而不是地址的形式固定您的起点来避免功能困惑。然后使用以下函数,您可以创建如果为 toInput 返回多个点,则是否要指向 To point。

代码是不言自明的。如果你不明白。在评论中回复。您要绘制的点之一应该从谷歌地理编码器系统返回确定点。在我的中,我使用起点作为确定点。并让它与我协调。所以没有机会得到

geo.getLocations(toInput, function (result){
//map.clearOverlays();
if (result.Status.code == G_GEO_SUCCESS) {
// ===== If there was more than one result, "ask did you mean" on them all =====
if (result.Placemark.length > 1) {
document.getElementById("textualdirectionscontainer").innerHTML = "Did you mean:";
// Loop through the results
for (var i=0; i<result.Placemark.length; i++) {
var p = result.Placemark[i].Point.coordinates;
document.getElementById("textualdirectionscontainer").innerHTML += "<br>"+(i+1)+": <a href='javascript:place(" +p[1]+","+p[0]+")'>"+ result.Placemark[i].address+"<\/a>";
}
}
// ===== If there was a single marker =====
else {
document.getElementById("textualdirectionscontainer").innerHTML = "";
var p = result.Placemark[0].Point.coordinates;
toLatLang = new GLatLng(p[1], p[0]);
// place(p[1],p[0]);
directionsPanel = $('textualdirectionscontainer');
directionsPanel.getElements('div').each(function(item) {
item.dispose();
});
directions.clear();
directions.loadFromWaypoints([hotelLatLng.toString(), toLatLang.toString()], {getPolyline:true});
/*var gp = directions.getPolyline();
map.addOverlay(gp); */
}
}
});

关于javascript - 如何在 google maps api 中创建带有建议的 "did you mean"链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4159958/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com