Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to use distanceBetween built in methog

 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 2848
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which class does that method belong to? What does its javadoc description say?
 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 2848
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got this as results.Please see attachment.
dis.jpg
[Thumbnail for dis.jpg]
 
Tim Moores
Bartender
Posts: 2848
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So all is good now?
 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 2848
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read it,but not clear how to get the distance.
 
Tim Moores
Bartender
Posts: 2848
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 2848
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read it.Anyway still i am unable to convert that value to KM.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic