Reputation: 1795
Can we use android location https://developer.android.com/reference/android/location/Location.html
inside the java standalone application. I have to find the distance between two lat/lng pairs. Now i am using
public double Haversine(double lat1,double lon1,double lat2,double lon2)
{
double R = 6372.8; // Earth Radius in Kilometers
double dLat = Deg2Rad(lat2 - lat1);
double dLon = Deg2Rad(lon2 - lon1);
double a = (Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(Deg2Rad(lat1)) * Math.cos(Deg2Rad(lat2)) *
Math.sin(dLon / 2) * Math.sin(dLon / 2));
double c = (2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)));
double d = R * c;
// Return Distance in Kilometers
return d;
}
public double Deg2Rad( double deg) {
public double Deg2Rad( double deg) {
return (deg * Math.PI / 180);
}
But the above code gives the air distance. But i need roadway distance. Please help me out.. thanks in advance
Upvotes: 1
Views: 122
Reputation: 8478
You can do this using Directions API of Google Maps
https://developers.google.com/maps/documentation/directions/
Good example is : http://javapapers.com/android/draw-path-on-google-maps-android-api/
This is example of Distance API of Google Map, but you can refer to it and use Directions API in same way
Upvotes: 1
Reputation: 2323
You can use Google direction API for this. http://code.google.com/apis/maps/documentation/directions/
I think you will find this helpful How To Calculate Distance Between Two Points in Driving Direction Mode in Android
Upvotes: 0