1

I have been working on Google Maps API for a Project which is fully based on Google Maps.

What am doing is :- Storing all the encoded Polyline in database for a particular route. Now i have current position(Latitude and Longitude) for user in database.

Now i want to match if any route Polyline from database is passing from the point of user position or does current user position comes in between any of the polyline with certain amount of range.

I have gone through lots of sites with different ideas but seems nothing is working in my way. Please help me out with this.

This link seems to be helpful, where do i need to pass polyline here. And i want the position of current user should me matched if it lies in between the polyline/ with some specified range.

But they are using Polygon , do i need to convert Polyline to Polygon? http://www.codeproject.com/Articles/62482/A-Simple-Geo-Fencing-Using-Polygon-Method

RKD
  • 405
  • 1
  • 5
  • 16

1 Answers1

1

You can accomplish these calculations by importing a geospatial library into your project or just adding some code.

Turf.js is a very interesting one in javascript and I believe turf.point-on-line is what you need. It'd take a location and a series of coordinates from your polygon and return the closest point on the polygon to your given location and the distance to it.

But you'll also find info on a similar answer

Community
  • 1
  • 1
Caio Iglesias
  • 594
  • 9
  • 24
  • Thank you for your answer. Cant we do this stuff in PHP. i need to do this in server side. – RKD Oct 28 '15 at 09:22
  • I could not find a good library in PHP, you'd have to write it all up. If you are able to install software on your server you could install the V8js engine http://php.net/manual/en/intro.v8js.php or run turf server side on node and call it from PHP http://stackoverflow.com/questions/8620636/trigger-node-js-file – Caio Iglesias Nov 06 '15 at 01:20
  • @RKD There's a [PHP library](http://geophp.net) that works with [GEOS](http://trac.osgeo.org/geos/) if you install (compile) the PHP extension. Unfortunately it does not expose two methods that would be what you needed on the bindings: [nearestPoints or closestPoints](http://trac.osgeo.org/geos/browser/branches/3.5/src/operation/distance/DistanceOp.cpp#L75) The only method it currently exposes that could be useful right off the bat is "distance", which returns the distance from two geometries. – Caio Iglesias Nov 12 '15 at 04:12