如何找到特定的局域网lng出现在路线上

时间:2014-09-03 14:29:28

标签: shortest-path

如何在两个位置之间的路径上找到特定的lat和long 谷歌方向服务

1 个答案:

答案 0 :(得分:0)

没有人回答这个问题。 最后我得到了自己的解决方案:D

让我告诉你!! 同时创建方向服务 所有边界都将存储在“路径”中。 所以使用这个数组。绘制多义线 然后使用几何函数“isLocationOnEdge”your_point,poly-lines array 它将返回true或false(就是它:D) 不要忘记添加学位..!默认度数为10e-10,因此将其更改为10e-2或其他。

      var request = {
        origin: document.getElementById("from").value,
        destination: document.getElementById("to").value,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
      }

      // Make the directions request

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

        if (status == google.maps.DirectionsStatus.OK) {
          directionsRenderer.setDirections(result);

          // Box around the overview path of the first route
          var path = result.routes[0].overview_path;


            var my_polyline = new google.maps.Polyline({
        path: path,
        geodesic: true,
        strokeColor: '#black',
        strokeOpacity: 1.0,
        strokeWeight: 2
      });

      my_polyline.setMap(map);



  var my_position=new google.maps.LatLng(12.9860932,80.1744085);


  console.log(google.maps.geometry.poly.isLocationOnEdge(my_position, my_polyline));


      var boxes = routeBoxer.box(path, distance);
      // alert(boxes.length);


    } else {
      alert("Directions query failed: " + status);
    }
  });
相关问题