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
Related
Working with the Google Maps API, I want to compute the intersection of a polyline and a polygon. I recall that polyline and polygon are sets of consecutive segments, the only difference is that a polygon is closed.
My first guess would be to check if any segment of the polyline intersects with any segment of the polygon. However my polylines can have up to 1e4 segments and my polygons up to 1e5 segments. Testing every pair would be too long.
Any idea of how to do that in a smarter way?
Is there a Geo API that I can query with an area name and receive back a polygon that represents the given area boundary?
Some form of a gazetteer that gives back a polygon instead of the latitude/longitude coordinates.
For example, if I search for "Santa Barbara" I would like to get back the array of the coordinates of the polygon seen on the picture below.
At the moment there is no such function in the public Google APIs. If you search for Santa Barbara using geocoding you will get the location with the viewport and bounding box. However you won't get a polygon around the area. When searching for Santa Barbara using Google Maps it uses a private API to show the polygon around the searched region.
One workaround would be to create your own polygons and save them to your database and then check if the lat/long is within those polygons.
Is there a possibilty to check that Polyline is in Polygon? Or I must check each points in Polyline containsLocation in Polygon?
I think about importing gpx files (my Polyline) and check what administrative area (my Polygons) contains this Polyline. I was thinking about reverse geocoding for each points in Polyline, but its impossible due to geocoding limitations. Any ideas?
You have to check every point of the Polyline against your Polygon. Take into account that a Polyline can be (according to DE-9IM):
Within your polygon (contained) = completely contained
Intersect your polygon = partially contained
Disjoint = not contained
So, a polyline can intersect two different Polygons (your Polyline can intersect two different administrative areas)
Problem
I have two coordinates: A B
Solution?
Can I see if coordinate A is within 50 meters of coordinate B using Google Maps API?
Other Solution?
If not, is there a way to do this without using google API?
computeDistanceBetween() from the Google Maps API v3 geometry library returns the straight line distance between two google.maps.LatLng objects (the default units are meters).
Be sure to include the geometry library
Each phone, amd many other geo apis have a function to calculate the distance between two lat,lon coordinates.
If you dont have one, then use the haversine distance formula.
I want to draw Polylines with the Google Maps JavaScript API. Is there a tool that will help me get the latitude and longitude points by just clicking on the map, then exporting an array of lat-long pairs?
I imagine something like the personalized maps service (My Places) in Google Maps where you can click-snap on the roads to specify your own driving directions. I'd like to take that one step further. That is, to export an array of lat-long pairs that specify the roads traveled.
I know this answer might be a little late but today I was trying to figure out what I believe to be the same issue as this question. So, you can draw the points on the map then get that encoded polyline with Google's Interactive Polyline Encoder Utility then I recommend using Mapbox polyline utility to convert the overview_polyline to latitude and longitude pairs values. The latitude and longitude pairs are also on Googles Utility but it is a bit of a hassle to continuously copy each coordinate.
For more information about the Mapbox Polyline Utility process:
http://zevross.com/blog/2014/09/23/convert-google-directions-to-geojson-points-or-polylines/
And here is Google's Encoder Utility:
https://developers.google.com/maps/documentation/utilities/polylineutility
You can use the Drawing Tools library:
http://code.google.com/apis/maps/documentation/javascript/overlays.html#drawing_tools
which will give you an encoded polyline. You can use that to draw a line, or you can decode it to get the specific points using the geometry library:
http://code.google.com/apis/maps/documentation/javascript/geometry.html