I try to create a WordPress plugin, that will use the Google maps directions in combination with bounds.
This is an application for km based charge, that has low cost/km into the bounds and high cost/km outside the bounds.
So the question is:
- Is there a way to know what is the distance from within the bounds point to the bounds border
- Is there a way to know what is the distance from a point outside the bounds to the bounds borders?
Note that the bounds area will be made with poligons. I have find the way to check if a point in the poligon or outside the poligon.
The problem is what I describe above in the list.
Yes, there’s a function in the API that measures distances between LatLngs.
It’s called : computeLength() in the geometry library.
Please read this
https://developers.google.com/maps/documentation/javascript/geometry
Distance and Area Functions
The distance between two points is the length of the shortest path between them. This shortest path is called a geodesic. On a sphere all geodesics are segments of a great circle. To compute this distance, call computeDistanceBetween(), passing it two LatLng objects.
You may instead use computeLength() to calculate the length of a given path if you have several locations.
Distance results are expressed in meters.
To compute the area (in square meters) of a polygonal area, call computeArea(), passing the array of LatLng objects defining a closed loop.