Calculate driving distance wtihout map
Can the driving distance be calculated without using a map, using only longitude and latitude?
I am coding a server side application and am try to avoid webservices, APIs and third party tools.
Can开发者_JAVA百科 you help me how to achieve this goal?
With the data you have
You could do a simple as-the-crow-flies calculation:
sqrt((lat1 - lat2)^2 + (long1 - long2)^2) = distance
You could do a simple Manhattan-distance calculation:
abs(lat1 - lat2) + abs(long1 - long2) = distance
You could do a simple globe-distance calculation. See: http://www.ehow.com/how_6353104_calculate-between-two-points-globe.html
These are accurate enough for some purposes, and might be accurate enough for your purposes, but are not completely accurate.
To be completely accurate, you will need more data points. Either road map data or known route information.
With road map data, you'll also have to implement a path-finding algorithm. Some examples of path finding algorithms are A-star and Dijikstra.
the ‘haversine’ formula calculates great-circle distances between the two points – that is, the shortest distance over the earth’s surface – giving an ‘as-the-crow-flies’ distance between the points ignoring any hills!, curves, roads, obstacles etc.
Haversine formula:
R = earth’s radius (mean radius = 6,371km)
Δlat = lat2− lat1
Δlong = long2− long1
a = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2)
c = 2.atan2(√a, √(1−a))
d = R.c
you might also look into the Spherical Law of Cosines
As you are calculating driving distance, your application does not need "as the crow flies distance" as it is the minimum distance, but definitely not the driving distance.
You have two options here. First, use a web service (Google Directions API) and create your own graph representation.
You have cut off the first option, so you need to look into the second option. The second option is, create a graph with the exact steps (a step is a distinct turn in a direction route) and make a huge local graph database to query (use OLAP maybe). This will call for a very robust database and my suggestion is still to use the first option, but you have the second option open too.
For the US you could always download the federal TIGER census map data and do your own calculations. If you want driving distance, you can't get around having map data of some sort.
http://arcdata.esri.com/data/tiger2000/tiger_statelayer.cfm?sfips=19
精彩评论