I have a point (lat, lng) X and a route drawn on the google map as shown below.
In my app, I have a rule:
If the distance between point X to the nearest point that is passed by
the route is less than 5 meters, then the route can be traversed.
Otherwise, if the distance between points X to the closest point
passed by the route is equal to or greater than 5 meters, then the
route cannot be traversed.
Is this rule can be applied by using google map service?
The Google Maps Javascript API has a Geometry library.
The Geometry library has a isLocationOnEdge function. See the documentation.
To determine whether a point falls on or near a polyline, or on or near the edge of a polygon, pass the point, the polyline/polygon, and optionally a tolerance value in degrees to google.maps.geometry.poly.isLocationOnEdge(). The function returns true if the distance between the point and the closest point on the line or edge falls within the specified tolerance. The default tolerance value is 10-9 degrees.
Related
On one project , I recovered all the coordinates of the polygons of different postal code.
When I search a zip code, I draw the polygon using the google api.
Now I would like to know whether a given polygon is so much distance from another .
Is that possible ?
By parsing all my geojson , I need to know if a random polygon is 5km from the polygon drawn .
There is computeDistanceBetween method from the geometry library...but its for two points. Is there the same for the distance between two polygons ?
Thx u for your help
Not sure if this would solve your problem but you can somehow use this library to compute distances within your polygon.
BDCCgeo.js
There is a function called bdccGeoDistanceToPolyMtrs(), you can measure the distance between a point and a polygon edge or polyline. Perhaps you can get a certain point on your first polygon and compare with with the second using this function.
Reference:
Distance from point within a polygon to polygon edge
I have few people stand in between a route from Location A to Location B using google map api 3.
Now i want to find out which all people(we have their GPS coords) are near to that route.
How can i find this.
With the Geometry Library.
https://developers.google.com/maps/documentation/javascript/reference#poly
Static method isLocationOnEdge()
Computes whether the given point lies on or near to a polyline, or the edge of a polygon, within a specified tolerance. Returns true when the difference between the latitude and longitude of the supplied point, and the closest point on the edge, is less than the tolerance. The tolerance defaults to 10-9 degrees.
You have to include the library in your API call:
http://maps.google.com/maps/api/js?libraries=geometry
I'm working on a project that picks random locations world-wide and need some functionality from Google Street View. I'm working with API v3 of Google Maps. The question I have is with the getPanoramaByLocation method. According to the Google docs, getPanoramaByLocation is :
"Retrieves the StreetViewPanoramaData for a panorama within a given radius of the given LatLng. The StreetViewPanoramaData is passed to the provided callback. If the radius is less than 50 meters, the nearest panorama will be returned."
The part I'm interested in is where it says "less than 50 meters, returns nearest panorama." So, for example, if I put in coordinates for somewhere in the middle of the Congo (where there isn't a street view for miles and miles), it should return a panorama of the nearest available street view. But it's not, it's returning null every time.
Is there a limit to how far away it looks?
Here's my Fiddle :
http://jsfiddle.net/nrJBP/1/
Thanks all, and hopefully this helps anyone in the future.
The service searches within the radius you give, as the docs state. You specify the maximum radius.
The service could find any Panorama data within the radius, except if you specify 50m, when it will always find the nearest (within that 50m).
You can use the google.maps.StreetViewStatus. If the request was successful, it will return OK. If there are no nearby panoramas, it will return ZERO_RESULTS.
Does anyone know if Google Maps consider elevations and the actual path on earth to calculate distance between two points or it only considers geographical locations for distance measurement?
If you are referring to using google.maps.DistanceMatrixRequest then yes, it considers the actual route when calculating distance, based on the option provided in travelMode
code.google.com reference
When there is no established route (at least known to google) i'm sure (from experience) the response is the distance 'as the crow flies' between 2 lat/long locations. [experience based off making the request for a path that bisected a large lake]
Is there a way to determine if a particular address is along a route within x miles? Is there support for this in the Google maps API?
I have a database of addresses and I am trying to figure out which locations lie along a given route as determined by the Google Maps API.
You can set the getPolyline option, on the GDirectionsOptions optional parameter, to the GDirections load request. This will get you the polyline data for the route.
Once you have this data you can iterate over each point in the polyline and determine the distance to each of your own datapoints (you can use the GLatLng distanceFrom method to calculate the distance).
Once you have the shortest distance to your route for each of your data points, you can and work out, based on some tolerance, if the point lies on the route.
Edit:
Although it is fine to call the GLatLng distanceFrom method repeatedly (it is just a utility method to get the distance between two points), I realized my answer simplifies the problem. To get an accurate distance from the route, you will need to determine the distance from the polyline between the closest two points (not just the distance from each point).
Bill Chadwick has "Distance of Point to Polyline or Polygon" code at the bottom of this page, which could prove useful.