sam_k
sam_k

Reputation: 6023

i want to get distance between two geo points in android

hi friends i want to get distance between two geo points. but here i get one problem in this my application . when i entered one geo point of sea location and one of any city so i get response in kml file nodata in kml file... i want to use google map to find find out distance between two cities..

Upvotes: 2

Views: 6368

Answers (2)

Dr1Ku
Dr1Ku

Reputation: 2910

As stated above, the Location Class is the way to go. Here is the code I have used :

Location locationA = new Location("point A");  

locationA.setLatitude(pointA.getLatitudeE6() / 1E6);  
locationA.setLongitude(pointB.getLongitudeE6() / 1E6);  

Location locationB = new Location("point B");  

locationB.setLatitude(pointB.getLatitudeE6() / 1E6);  
locationB.setLongitude(pointB.getLongitudeE6() / 1E6);  

double distance = locationA.distanceTo(locationB);

In this example, both pointA and pointB are instances of the GeoPoint class.

Upvotes: 7

Umesh Kacha
Umesh Kacha

Reputation: 13666

http://developer.android.com/reference/android/location/Location.html

Look for distanceBetween or distanceTo methods

Upvotes: 1

Related Questions