Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

JavaScript
$.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) { }
});
Posted
Updated 7-May-18 16:22pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900