wood burning stoves*
The moose likes Android and the fly likes how to use distanceBetween built in methog Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "how to use distanceBetween built in methog " Watch "how to use distanceBetween built in methog " New topic
Author

how to use distanceBetween built in methog

sam liyanage
Ranch Hand

Joined: Nov 25, 2008
Posts: 1032
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
Rancher

Joined: Sep 21, 2011
Posts: 2408
Which class does that method belong to? What does its javadoc description say?
sam liyanage
Ranch Hand

Joined: Nov 25, 2008
Posts: 1032
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 liyanage
Ranch Hand

Joined: Nov 25, 2008
Posts: 1032
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
Rancher

Joined: Sep 21, 2011
Posts: 2408
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 ?

The javadocs talk about that, don't they.
sam liyanage
Ranch Hand

Joined: Nov 25, 2008
Posts: 1032
I got this as results.Please see attachment.


[Thumbnail for dis.jpg]

Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
So all is good now?
sam liyanage
Ranch Hand

Joined: Nov 25, 2008
Posts: 1032
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
Rancher

Joined: Sep 21, 2011
Posts: 2408
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 liyanage
Ranch Hand

Joined: Nov 25, 2008
Posts: 1032
I read it,but not clear how to get the distance.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
That's odd. One would think that "The computed distance is stored in results[0]." doesn't leave much room for misunderstandings.
sam liyanage
Ranch Hand

Joined: Nov 25, 2008
Posts: 1032
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
Rancher

Joined: Sep 21, 2011
Posts: 2408
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 liyanage
Ranch Hand

Joined: Nov 25, 2008
Posts: 1032
I read it.Anyway still i am unable to convert that value to KM.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to use distanceBetween built in methog
 
Similar Threads
Distance between two Airports
architectural advice on iterating over large datasets
calculate object position to the top edge of the browser
Code Help
A Star Algorithm on google map