如何知道路线上是否存在某个点? [英] How to know if a point exists on a route?
本文介绍了如何知道路线上是否存在某个点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何知道一个点是否在折线中?
这是我的代码,我使用谷歌地图(islocationonedge)的例子,但它不起作用,它说点是en路线,但实际上它不是
我想知道这个点是否在距离路线约50米的范围内
我不知道我是什么做错了,请帮帮我
我尝试过:
$。ajax({
url: / Home / GetPolyline ,
类型: GET,
contentType:< span class =code-string> application / json; charset = utf-8,
datatype: JSON ,
成功:功能(结果){
// result = 0:{latitud: - 21.532962,longitudinal: - 64.742054}
// 1:{latitud: - 21.532713,longitudinal: - 64.740906}
// < span class =code-comment> 2:{latitud: - 21.532753,longitudinal: - 64.740069}
// 3:{latitud: - 21.532810,longitudinal: - 64.739021}
alert( 你在这里)
var myPosition = new google.maps.LatLng(-21。 532863 , - 64。 741526 );
// var myPosition = new google.maps.LatLng(-21.578561,-64.690277);
var points = new google.maps.MVCArray();
points = result;
var cascadiaFault = new google.maps.Polyline({
points
});
cascadiaFault.setMap(map);
if (google.maps.geometry.poly.isLocationOnEdge(myPosition,cascadiaFault, 0 。 001 )){
alert( 重新定位跨度>)!;
}
else {
alert( 你在路线)
//
}
},
错误:功能(数据){}
});
解决方案
.ajax({
url: / Home / GetPolyline,
类型: GET ,
contentType: application / json; charset = utf-8,
数据类型: JSON ,
成功:功能(结果){
// result = 0:{latitud: - 21.532962,longit ud: - 64.742054}
// 1:{latitud: - 21.532713 ,longitudinal: - 64.740906}
// 2:{latitud: - 21.532753 ,纵向: - 64.740069}
// 3:{latitud: - 21.532810,longitudinal: - 64.739021}
alert( 你在这里)
var myPosition = new google.maps.LatLng(-21。< span class =code-digit> 532863 , - 64。 741526 );
// var myPosition = new google.maps.LatLng(-21.578561,-64.690277);
var points = new google.maps.MVCArray();
points = result;
var cascadiaFault = new google.maps.Polyline({
points
});
cascadiaFault.setMap(map);
if (google.maps.geometry.poly.isLocationOnEdge(myPosition,cascadiaFault, 0 。 001 )){
alert( 重新定位跨度>)!;
}
else {
alert( 你在路线)
//
}
},
错误:功能(数据){}
});
How to know if a point is in a polyline?
this is my code where I use the example of google maps (islocationonedge) but it does not work, it says that the point is en route but in reality it is not
I want to know if the point is within an approximate range of 50 meters tolerance from the route
I do not know what I'm doing wrong, please help me please
What I have tried:
$.ajax({
url: "/Home/GetPolyline",
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: JSON,
success: function (result) {
//result=0:{latitud: "-21.532962", longitud: "-64.742054"}
// 1:{latitud: "-21.532713", longitud: "-64.740906"}
// 2:{latitud: "-21.532753", longitud: "-64.740069"}
// 3:{latitud: "-21.532810", longitud: "-64.739021"}
alert("you are here")
var myPosition = new google.maps.LatLng(-21.532863, -64.741526);
//var myPosition = new google.maps.LatLng(-21.578561, -64.690277);
var points = new google.maps.MVCArray();
points = result;
var cascadiaFault = new google.maps.Polyline({
points
});
cascadiaFault.setMap(map);
if (google.maps.geometry.poly.isLocationOnEdge(myPosition, cascadiaFault, 0.001)) {
alert("Relocate!");
}
else {
alert("you are in route")
//
}
},
error: function (data) { }
});
解决方案
.ajax({ url: "/Home/GetPolyline", type: "GET", contentType: "application/json; charset=utf-8", datatype: JSON, success: function (result) { //result=0:{latitud: "-21.532962", longitud: "-64.742054"} // 1:{latitud: "-21.532713", longitud: "-64.740906"} // 2:{latitud: "-21.532753", longitud: "-64.740069"} // 3:{latitud: "-21.532810", longitud: "-64.739021"} alert("you are here") var myPosition = new google.maps.LatLng(-21.532863, -64.741526); //var myPosition = new google.maps.LatLng(-21.578561, -64.690277); var points = new google.maps.MVCArray(); points = result; var cascadiaFault = new google.maps.Polyline({ points }); cascadiaFault.setMap(map); if (google.maps.geometry.poly.isLocationOnEdge(myPosition, cascadiaFault, 0.001)) { alert("Relocate!"); } else { alert("you are in route") // } }, error: function (data) { } });
这篇关于如何知道路线上是否存在某个点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文