【问题标题】:Google maps direction renderer exact match only谷歌地图方向渲染器仅精确匹配
【发布时间】:2013-07-23 03:32:23
【问题描述】:

我正在使用 DirectionRenderer(gmap3) 来显示用户方向。问题是即使找不到完全匹配,它也会显示匹配。例如:SomeFakePlace,myRealCity 将匹配 myRealCity,即使它无法匹配 SomeFakePlace。

所以它显示了从城市中心到该地点的方向,而不是。目的地是固定的(myLatLng)

如果找不到路线,我希望它返回 null 并且不显示路线。我有不错的错误显示来处理这个问题。

  $("#map-canvas-single").gmap3({ 
          getroute:{
            options:{
                origin:$("#directions-from").val(),
                destination:myLatlng,
                travelMode: google.maps.DirectionsTravelMode.DRIVING
            },
            callback: function(results){
                console.log(results);
                   var point= results.routes[0].overview_path[0]
                    window.directionMarker = new google.maps.Marker({
                        position: new google.maps.LatLng(point.jb,point.kb),
                        title:$("#directions-from").val(),
                        //icon:"http://maps.google.com/mapfiles/ms/icons/<?php if($this->listing->type=="pg"):?>green<?php else: ?>purple<?php endif;?>-dot.png"

                    });
                    window.directionMarker.setMap($(this).gmap3("get"));

             if(!results)
                 noty({text:"Place not found!",type:"error"});
             else
             {
                 $(this).gmap3({
                     directionsrenderer:{
                       container: $("#directions-container"),
                          id:"directions",
                       options:{
                         directions:results,
                        suppressMarkers :true //<<Look here>>
                       } 
                     }
                   });

            }
          }
        }
      });

代码运行良好。我认为这是方向渲染器服务的错,而不是 gmaps。我确信htere必须是完全匹配的某个参数

【问题讨论】:

  • 没有办法。 :(

标签: google-maps-api-3 jquery-gmap3


【解决方案1】:

我不熟悉 Google Maps API,但我要做的是对源地址进行地理编码查找并找到 lat、lng。您通常会获得具有置信度的坐标,因此您可以有一个最小阈值,低于该阈值会引发错误。

https://developers.google.com/maps/documentation/geocoding/

另外,不要忘记地图任务。

http://developer.mapquest.com/web/products/dev-services/geocoding-ws

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-09
    • 2012-05-01
    • 2013-07-19
    • 2010-11-12
    相关资源
    最近更新 更多