• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to use distanceBetween built in methog

 
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which class does that method belong to? What does its javadoc description say?
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got this as results.Please see attachment.
dis.jpg
[Thumbnail for dis.jpg]
 
Tim Moores
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So all is good now?
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I read it,but not clear how to get the distance.
 
Tim Moores
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I read it.Anyway still i am unable to convert that value to KM.
 
You ought to ventilate your mind and let the cobwebs out of it. Use this cup to catch the tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic