Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old September 8th, 2011, 06:20 AM   #1 (permalink)
Junior Member
 
Join Date: Jul 2011
Posts: 27
 
Device(s):
Thanks: 9
Thanked 2 Times in 2 Posts
Unhappy Find the distance between 2 Latitudes and Longitudes ?

Hi,

Below is the code to find distance between 2 Latitudes and Longitudes. But it is not working proper way.

////////////////////////////////

public double lanLatDistance(double oldlan, double oldlat,
double plan, double plat) {
double R = 6371; // earth’s radius (mean radius = 6,371km)
double dLat = Math.toRadians(oldlan - plan);

double dLon = Math.toRadians(oldlat - plat);
double a = (Math.sin(dLat / 2) * Math.sin(dLat / 2)) +
(Math.cos(Math.toRadians(oldlan)) * Math.cos(Math.toRadians(plan)) * Math.sin(dLon / 2) * Math.sin(dLon / 2));
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
double distance = R * c;
//System.out.println("distance" + distance);

return distance;
}

///////////////////////////////

Please help me to find out where I am doing mistake.

Please mention in the piece of codes.


Thanks and Regards,
Andy

Arthur Andy is offline  
Reply With Quote
Sponsors
Old September 8th, 2011, 03:30 PM   #2 (permalink)
Junior Member
 
Join Date: Jul 2011
Posts: 24
 
Device(s):
Thanks: 0
Thanked 2 Times in 2 Posts
Default

I used this equation in an iPhone app and i had the same difficulty. I found the problem was in a trig function. I think the function that was playing up for me was the atan2() function.

You should track down the fault by making sure that each line of code gives you the correct answer. Should be easy enough using break points and a calculator.
Shocker_33 is offline  
Reply With Quote
Old September 8th, 2011, 05:56 PM   #3 (permalink)
Member
 
Join Date: Jun 2010
Posts: 363
 
Device(s): Samsung Galaxy S (international)
Thanks: 72
Thanked 57 Times in 55 Posts
Default

please use the [CODE] tag .. reading like this gives me headache >.<

try checking this

http://bit.ly/r7eyoO
__________________
if I ever said anything that helped you , the thanks button is where your cursor/finger should head to
JiMMaR is offline  
Reply With Quote
Reply

Bookmarks

Tags
android, java


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 11:45 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo