程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Google Maps API:在以色列两点之间找到一条路线大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Google Maps API:在以色列两点之间找到一条路线?

开发过程中遇到Google Maps API:在以色列两点之间找到一条路线的问题如何解决?下面主要结合日常开发的经验,给出你关于Google Maps API:在以色列两点之间找到一条路线的解决方法建议,希望对你解决Google Maps API:在以色列两点之间找到一条路线有所启发或帮助; || 我试图在我在HTML页面上手动输入的两点之间找到一条路线,但我得到了ZERO_RESulTS返回值。 用户输入两个位置src_address = \“ Tel Aviv \”和dst_address = \“ Haifa \”。 我通过为每个地址两次调用geocoder.geocode来获得它们的几何位置。然后设置: src_latlng = results [0] .geometry.LOCATIOn; dst_latlng = results [0] .geometry.LOCATIOn; 但是,当询问路由器时,我得到ZERO_RESulTS: 这是代码:
    <!DOCTYPE HTML>
<HTML>
<img src=\"globe123.jpg\" wIDth=\"72\" height=\"75\"/> 
<head>
<Meta name=\"vIEwport\" content=\"initial-scale=1.0,user-scalable=no\"/>
<Meta http-equiv=\"content-type\" content=\"text/HTML; charset=UTF-8\"/>
<title>Google Maps JavaScript API v3 Example: GeoCoding Simple</title>
<link href=\"http://code.Google.com/APIs/maps/documentation/JavaScript/examples/default.CSS\" rel=\"stylesheet\" type=\"text/CSS\" />
<script type=\"text/JavaScript\" src=\"http://maps.Google.com/maps/API/Js?sensor=false\"></script>



<script type=\"text/JavaScript\">
  var directiondisplay;
  var directionsservice = new Google.maps.Directionsservice();

  var geocoder;
  var map;
  var geodesic;
  var poly;
  var src_latlng;
  var dst_latlng;

  function initialize() {
    directionsdisplay = new Google.maps.DirectionsRenderer();

    geocoder = new Google.maps.Geocoder();
    var latlng = new Google.maps.LatLng(-34.397,150.644);
    var myOptions = {
      zoom: 8,center: latlng,mapTypEID: Google.maps.MapTypEID.roaDMAP
    }
    map = new Google.maps.Map(document.getElementByID(\"map_canvas\"),myOptions);


    var polyOptions = {
      strokecolor: \'#FF0000\',strokeOpacity: 1.0,strokeWeight: 3
    }
    poly = new Google.maps.polyline(polyOptions);
    poly.setMap(map);
    directionsdisplay.setMap(map);
    // Add a Listener for the click event
    //Google.maps.event.addListener(map,\'click\',addLOCATIOn);
  }

  function codeAddress() {
    var src_address = document.getElementByID(\"SRC_ADDR\").value;
    var dst_address = document.getElementByID(\"DST_ADDR\").value;

    geocoder.geocode( { \'address\': src_address},function(results,status) {
      if (status == Google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.LOCATIOn);
        var path = poly.getPath();
        path.push(results[0].geometry.LOCATIOn);
        src_latlng = results[0].geometry.LOCATIOn;
        var marker = new Google.maps.Marker({
            map: map,position: results[0].geometry.LOCATIOn
        });
      } else {
        alert(\"Geocode was not successful for the following reason: \" + status);
      }
    });
    geocoder.geocode( { \'address\': dst_address},status) {
      if (status == Google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.LOCATIOn);
        map.setZoom(8);

        var path = poly.getPath();
        path.push(results[0].geometry.LOCATIOn);
        dst_latlng = results[0].geometry.LOCATIOn;
        var marker = new Google.maps.Marker({
            map: map,position: results[0].geometry.LOCATIOn
        });


        calcRoute();

      } else {
        alert(\"Geocode was not successful for the following reason: \" + status);
      }
    });



  }

  function calcRoute() {



      var start = src_latlng;
      var end = dst_latlng;
      var request = {
        origin:start,desTination:end,travelmode: Google.maps.DirectionsTravelmode.DRIVING
      };

      directionsservice.route(request,function(result,status) {

        if (status == Google.maps.Directionsstatus.OK) {         
          directionsdisplay.setDirections(result);
        } else {
            alert(status);            
        }    
        });
    }


</script>
</head>
<body onload=\"initialize()\">


  <div style=\"text-align:left\">
  source: <input ID=\"SRC_ADDR\" type=\"textBox\" value=\"Tel-Aviv,Israel\">
  DesTination: <input ID=\"DST_ADDR\" type=\"textBox\" value=\"Haifa,Israel\">
  <input type=\"button\" value=\"Calculate Travel Time\" onclick=\"codeAddress()\">
  </div>
  <div ID=\"map_canvas\" style=\"height:40%;wIDth:40%;top:120px\"></div>
  <!-- <div ID=\"map_canvas\" style=\"wIDth: 320px; height: 480px;\"></div> 
  -->



</body>
</HTML>

解决方法

Google尚不支持以色列的Maps API,因此
directionsservice.route
函数调用返回了ZERO_RESULTS状态。 请在此处查看Google \'s受支持地区的地图覆盖范围详细信息工作表。指向电子表格的直接链接在这里。,您好,您可以使用此代码获取源和目的地之间的路线 函数setRoute() { var fromAddress = document.getElementById(\“ txtfromAddress \”)。value; var toaddress = document.getElementById(\“ txttoaddress \”)。value; if(fromAddress!= \“ \” && toaddress!= \“ \”) { if(!fromAddress &&!toaddress) { 警报(\'找不到路由\'); } GDir1.load(\“ from:\” + fromAddress + \“ to:\” + toaddress); } 其他 { 警报(\'需要路线指示\'); } },* http://gmaps-samples.googlecode.com/svn/trunk/mapcoverage_filtered.html* 查看它是否覆盖您所在的区域,其中包括街景视图或卫星视图的详细视图等(可用) GL

大佬总结

以上是大佬教程为你收集整理的Google Maps API:在以色列两点之间找到一条路线全部内容,希望文章能够帮你解决Google Maps API:在以色列两点之间找到一条路线所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。