I have divided a city into number of regions using Google map's Polyline constructor.
Now I have to float a number of routes within each region and check which have a common road map.
Let me give a example taking only 2 routes
I want to show 4 locations on Google Map: A
, B
, A'
and B'
.
A--->B
constitutes route 1.
A'--->B'
constitutes route 2.
Now my requirement is to check whether route 1 comes within the same route as route 2.
I have to do the same for multiple routes. But initially I want know whether it can be done in Google maps for two routes.
I followed this post https://groups.google.com/forum/?fromgroups=#!topic/google-maps-api/0tU9wr2eMpI and have done the same.
But this code only checks whether the route falls in straight line. It does not consider the road map
Here's a quick and dirty example using google.maps.geometry.poly.isLocationOnEdge.
Loop through the path of the polyline's MVC array and check it against the other polyline.
path.forEach(function(element, index) {
console.log(element);
if (google.maps.geometry.poly.isLocationOnEdge(element, polyline)) {
console.log(element + " on edge");
} else {
console.log(element + " not on edge");
}
});
Edit: Updated the fiddle so you could see where the other line was and modified the coords a bit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With