Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining whether a route falls within another route in Google Map

enter image description hereI 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

like image 551
Maclean Pinto Avatar asked Sep 06 '25 04:09

Maclean Pinto


1 Answers

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.

like image 61
Rick Avatar answered Sep 09 '25 06:09

Rick