如何制作“你的意思是”吗?谷歌地图 API 中的建议链接?

发布于 2024-10-02 04:40:17 字数 208 浏览 4 评论 0原文

我正在尝试使用 google 地图 api 制作一个网络应用程序,以提供指示。现在,它可以很好地提供指示,除非用户输入错误的内容,它要么不显示任何内容,要么尝试找出答案并给出错误的地址。我想提供这样的功能:如果地址无法识别,它会显示“您的意思是”,然后提出与您尝试输入的内容接近的建议。我在谷歌代码中找不到任何谈到这一点的内容,但我想知道是否有人知道这是否可能,以及我该怎么做?

谢谢!

I'm trying to make a web application with google maps api, that gives directions. Right now, It gives directions fine unless the user types in something wrong, it either doesn't show anything or it tries to figure it out and gives the wrong address. I want to make functionality where if the address is not recognized it has "did you mean" and then make a suggestion that's close to what you were trying to enter. I couldn't find anything in the google code that talked about that, but I'm wondering if anyone knows if it's possible, and how I can do it?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余厌 2024-10-09 04:40:17

仅当提供给 loadFromWayPoints() 的输入映射到地球上的任何确定点时,loadFromWayPoints() 才会绘制折线。您可以通过以纬度和经度形式(而不是地址)固定出发点来避免操作混乱。然后使用以下函数,您可以创建如果为 toInput 返回多个点,您的意思是 To 点吗?

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

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); */
            } 
        }
    });

loadFromWayPoints() draws polyline only if the inputs provided to it maps to any definite point on the earth. You can avoid the confusion to function by fixing your from point in form of latitude and longitude, instead of address. Then using following function you may create Did you mean for To point if multiple points returned for toInput.

Code is self explanatory. If you dont understand. Reply in comment.
One of the point you want to plot should return definite point from google geocoder system.
In my I used the from point as definite point. And had it coordinates with me. So there is no chance of getting

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); */
            } 
        }
    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文