【问题标题】:How to make a "did you mean" link with suggestions, in google maps api?如何在谷歌地图 api 中创建带有建议的“您的意思是”链接?
【发布时间】:2011-05-08 18:43:14
【问题描述】:

我正在尝试使用 google maps api 制作一个 web 应用程序,它可以提供方向。现在,它给出的方向很好,除非用户输入错误,它要么不显示任何东西,要么试图弄清楚并给出错误的地址。我想提供功能,如果地址未被识别,它具有“您的意思”,然后提出与您尝试输入的内容接近的建议。我在 google 代码中找不到任何关于此的内容,但我想知道是否有人知道这是否可能,以及我该怎么做?

谢谢!

【问题讨论】:

    标签: javascript maps google-maps-api-3 google-maps-api-2


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-18
      • 2011-10-22
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多