I'll find a route between two places, for example using google maps. I'd like to divide the route to kilometers (two following places will be at a distance of 1 km), and get GPS coordinations of these places. This is because then I'll be able to get exacly the coordinations of, for example, 5th kilometer on the route. Could you please advice me how to achieve it?
This is extremely nontrivial. Is say your best bet is to find an algorithm to load the bearing between two points, then one to load a coordinate given a start point, distance, and bearing. This could give you it, but only if the data contained only straight lines. Since I assume the Google Maps API only gives you the turns the user has to make, this approach will be inaccurate when there are bends in roads. You'd need GIS data for roads and what will undoubtedly turn into a complicated algorithm to find something like this. It's definitely doable, but that's l how I'd start. Look into the Census TIGER road data, it should help.
Unless, of course, I'm wrong and the API does actually give enough points to cleanly map it, in which case those functions should be easy to find and implement.
This will only work if you have the polyline as a sequence of lat/lon (or other) coordinates, wherever you get that from.
Then you start at the beginning an iterate through the lines (point[i], point[i+1]).
THis distance you calculate with standard API.
while itersting you sum up the distance.
Once you exceed the 1000m, you know that the splitting point (the 1000m marker) is at line segment [i,i+1].
To calculate the exact position where on the line that is, you take the total summed meters from previous segment, and the value of this segment and do a linear interpolation.
The working code is a bit complexer: there can be multiple markes within one segement.
But first find out where you get the polyline from, whitou that it will not work.
Related
Is there a simple way to calculate the closest distance between a route (directions between two cities for example) and a GPS coordinate using the Google Maps API?
One appoach I can think of is to translate the route into a set of GPS coordinates and calculate the distance to each coordinate. Is there a better way of doing this?
One appoach I can think of is to translate the route into a set of GPS
coordinates and calculate the distance to each coordinate. Is there a
better way of doing this?
Yes there is a much better way.
The first part is correct: translate to a polyline of lat/lon coordinates.
However the second is to simple. You want the shortest distance to the line segment not the the next corner point, that is the start or end of the line.
In school you used the hessian normal distance. However this formula calculates just the distance to an infinite line. In case of a polyline you have an sequence of line segments.
So you need a formula for "distance to line segment". This one you can find using that search terms.
Having this formula implemented, you interate over all line segments each defined by two points (polyPoint[i], polyPoint[i+1]) and take the minimum of the distance.
Don't forget to transform the current line segement to cartesian (x,y) space, because the usualy formulas, do not work on spehrical coordinates.
This approach is more complex, but gives exact results. Remember a line on a route if often 400-700 meters long. So the simple approach you asked, gives in this case an error of 200-350m if you are in the middle between the two points.
I'm using an L80 GPS module together with my 8-bit processor. GPS module responds with a massage in NMEA format, giving me information about the date, time, latitude, longitude, altitude (if possible), number of satellites etc.
Latitude and longitude information of NMEA are in the form of degrees and minutes (DD°MM.mmm').
I'm able to convert them into only degrees notation (DD.dddddd°).
I have the following problem: Given a particular location (e.g. 48.858125, 2.294398) and a safety radius of, let's say, 50 meters (no more than 300 meters), how to determine weather (a, b) point is within a safety circle or not?
Can you help me figuring out the math hiding behind?
In short, I would like you to help me determine distance in meters between two points on Earth represented in angular coordinate system. Are there any math guru willing to help me?
Note that my point of calculations is my processor.
I know that, having latitudes and longitudes in degrees, my points are represented in an angular coordinate system, not Cartesian (linear) one.I also know that Universal Transferse Mercator (UTM) representation of points on Earth is in Cartesian coordinate system. Is it, maybe, easier to transform degree notation (DD.dddddd°) into UTM notation? I know there are on-line tools that are able to do a conversion. However, I don't know the math.
Thank you very much for your time and effort to help me.
Sincerely,
Bojan
You can simply find distance b/w two points by longitude and latitude.
you can find reference code on this link.
Hope this helps.
Just use the haversine formula to calcualte the distance between two points on earth.
Search for term "haversine" and the name of your programming language.
Is it, maybe, easier to transform to UTM
No for sure not. It is very complex, and it gets extremly complex when the two points are located in different UTM zones.
I'm trying to generate some annotations on a map. Currently, I'm using openstreetmap but the query is general. I have two end points on a map and a corpus of few selected points I would like to highlight.
The two endpoints are given in the form lat, long
<walkSteps>
<distance>9.742464221826811</distance>
<streetName>5th St NW</streetName>
<absoluteDirection>EAST</absoluteDirection>
<stayOn>false</stayOn>
<bogusName>false</bogusName>
<lon>-84.3937361115149</lon>
<lat>33.77692965678444</lat>
<elevation/>
</walkSteps>
<walkSteps>
<distance>508.2608917548245</distance>
<relativeDirection>LEFT</relativeDirection>
<streetName>Fowler St NW</streetName>
<absoluteDirection>NORTH</absoluteDirection>
<stayOn>false</stayOn>
<bogusName>false</bogusName>
<lon>-84.39363494600667</lon>
<lat>33.77692904176358</lat>
<elevation/>
</walkSteps>
My aim is to highlight those points on the map, which are present in the corpus and lie in the line connecting these two points.
How can I go about querying the corpus for the same? Annotating on map given lat, lng is not an issue
Rounding errors will prevent you from directly doing as you want. What you should be doing instead is determining the great-circle path between the two end points and highlighting those members of the corpus which are within a certain distance of the great circle route. This is known as the cross-track distance or cross-track error. Formulas for computing the cross-track distance can be found at one of the standard reference sites for geospatial equations but there are others as well.. The problem then becomes one of searching for points in the corpus which are close enough to the great circle path between the two end points.
I would like to find all points that are within N miles of a given area.
E.g. the area is California: Find all points that are within 50 miles of the border of California (not the middle of California).
When using Google Maps the distance is calculated using 'the middle' of the given location, but I need to calculate the distance using the borders of the given location. The location could be any zip code, city or country.
Could that be done by drawing a polygon using California's coordinates on a map and calculate the distance to location B using the points of the polygon?
Is there a more elegant solution to this? Any ideas?
Thanks!
I'm not sure if I understand your requirements completely, but I will give it a try with different interpretations:
1. You want to filter own map points:
This can be done with any GIS or a own service that offers a call like my_points_in_area(bbox). Bbox means here boundingbox and is the 2x lat/lon pair describing the rectangle around your given centerpoint. If you want to be accurate and really just deliver whats within 100km, you might need to test the distance to the POIs once more, as the rectangle will also include points that are a bit more far away.
2. You want to filter OSM data:
You might use a reverse-geocoding service as Nominatim to get informations about points of interests that are within this distance: http://wiki.openstreetmap.org/wiki/Nominatim
Otherwise import the OSM data using osmosis to a PostGIS DB. AFAIK there is (currently) no DB tool for Oracle: http://wiki.openstreetmap.org/wiki/Oracle
I'm sorry if I missed your question, but then please add more details :)
There is a function in google maps geometry library
interpolate(from:LatLng, to:LatLng, fraction:number)
which finds a point between two other points:
A--X--B
I need something very similar, find a point further along the line:
A--B--X
Interpolate does not accept fraction>1 so I cannot use it. Is there some simple way to calculate the point?
I want to achieve given distance between A and X points.
EDIT: In my application the distance was really small so I used fromLatLngToPoint conversion and linear interpolation, which get good enough results on small area.
You can calculate bearing, then find destination point with code from this excellent page