This week's book giveaway is in the Testing forum.We're giving away four copies of The Way of the Web Tester: A Beginner's Guide to Automating Tests and have Jonathan Rasmusson on-line!See this thread for details.
Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

how to use distanceBetween built in methog

sam liya
Ranch Hand
Posts: 1243
I need to calculate distance between two locations.I have longitudes and latitudes for both location.So i need to know how to use distanceBetween method to calculate distance between them ?
I mean on what object should i call distanceBetween method ?

Tim Moores
Bartender
Posts: 3024
47
Which class does that method belong to? What does its javadoc description say?

sam liya
Ranch Hand
Posts: 1243
this is my main class

when this programm runs it display the current location.When i going to search location it gives me a problen.because when distanceBetween method run on null location.see the code.
location.distanceBetween(latitudeE6,longitudeE6, SearchlatitudeE6, SearchlongitudeE6,result);

how to aviod this ?

sam liya
Ranch Hand
Posts: 1243
distanceBetween methods returns float array.So what are the results in array.I means it is returns distance in meters why it returns array ?

Tim Moores
Bartender
Posts: 3024
47
One error is right here:
location=this.location;

distanceBetween methods returns float array.So what are the results in array.I means it is returns distance in meters why it returns array ?

sam liya
Ranch Hand
Posts: 1243
I got this as results.Please see attachment.
dis.jpg

Tim Moores
Bartender
Posts: 3024
47
So all is good now?

sam liya
Ranch Hand
Posts: 1243
Not yet.I have no clear idia what are those values.I mean in array .

I search here.unable to find
http://developer.android.com/reference/android/location/Location.html#distanceBetween(double, double, double, double, float[])

Tim Moores
Bartender
Posts: 3024
47
And yet, it says so right there. If you don't know what WGS84 (or the bearing it defines) is - its Wikipedia page would be a good starting point to learn about it.

sam liya
Ranch Hand
Posts: 1243
I read it,but not clear how to get the distance.

Tim Moores
Bartender
Posts: 3024
47
That's odd. One would think that "The computed distance is stored in results[0]." doesn't leave much room for misunderstandings.

sam liya
Ranch Hand
Posts: 1243
Anyway when i search distance from this the 0th element give me 1.1317398E7.So the distance should be is 1.317 Km.
1)Is it correct ?
2)I think this is shortest distance.When i check using google map the distance is 2.8 Km.I think this is happen Google map get distance from road wise.Anyway i need to calculate distance road wise.is it possible ?

Tim Moores
Bartender
Posts: 3024
47
1.1317398E7 m is 1.317 km? How do you figure that?

Once again: As the javadocs state, "Distance [is] defined using the WGS84 ellipsoid". That's probably pretty close to "as the crow flies".

The Google Maps API most likely has a web service you can call to get the streetwise distance between two locations.

sam liya
Ranch Hand
Posts: 1243
I read it.Anyway still i am unable to convert that value to KM.