View Single Post
Old 11-13-2010, 01:40 AM  
borked
Totally Borked
 
borked's Avatar
 
Industry Role:
Join Date: Feb 2005
Posts: 6,284
Quote:
Originally Posted by goodsites View Post

I'll re paraphrase

Providing a lat and long, and a range in miles, i need to create a second lat and long based off this..

Can anyone help?
How the hell can you do that without providing a heading?

It's like saying "stand in place X and walk 10 miles and tell me where you are". You could be anywhere depending on which heading you set off on....

here is a function that tells you the compass heading based on 2 pairs of lat/lon (lat1/lon1 are the starting point. The heading returned is heading toward lat2/lon2)

Quote:
public function heading($lat1, $lon1, $lat2, $lon2) {
$d = acos(sin($lat1)*sin($lat2)+cos($lat1)*cos($lat2)*c os($lon1-$lon2));
$angle_radians = acos((sin($lat2)-sin($lat1)*cos($d))/(sin($d)*cos($lat1)));
$angle_degrees = round( ( ( 180 / pi()) * $angle_radians ),2);

$heading = compass($angle_degrees);

$array['angle'] = $angle_degrees;
$array['heading'] = $heading;
return $array;
}

public function compass($a) {

if ($a == 0 && $a <= 11.25)
return 'N';

if ($a > 11.25 && $a <= 33.75)
return 'NNE';

if ($a > 33.75 && $a <= 56.25)
return 'NE';

if ($a > 56.25 && $a <= 78.75)
return 'ENE';

if ($a > 78.75 && $a <= 101.25)
return 'E';

if ($a > 101.25 && $a <= 123.75)
return 'ESE';

if ($a > 123.75 && $a <= 146.25)
return 'SE';

if ($a > 146.25 && $a <= 168.75)
return 'SSE';

if ($a > 168.75 && $a <= 191.25)
return 'S';

if ($a > 191.25 && $a <= 213.75)
return 'SSW';

if ($a > 213.75 && $a <= 236.25)
return 'SW';

if ($a > 236.25 && $a <= 258.75)
return 'WSW';

if ($a > 258.75 && $a <= 281.25)
return 'W';

if ($a > 281.25 && $a <= 303.75)
return 'WNW';

if ($a > 303.75 && $a <= 326.25)
return 'NW';

if ($a > 326.25 && $a <= 348.75)
return 'NNW';

if ($a > 348.75 && $a <= 360)
return 'N';


}
I'll let you work the two examples I gave you to do what you search for ;)
If you want me to figure it out, I'll have to charge you but you have the 2 most important functions there before you to figure it out...
__________________

For coding work - hit me up on andy // borkedcoder // com
(consider figuring out the email as test #1)



All models are wrong, but some are useful. George E.P. Box. p202

Last edited by borked; 11-13-2010 at 01:42 AM..
borked is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote