0
votes

What is the easiest way to add a distance (100 miles) to a latitude/logitude pair, and a direction (north, etc) to get a new lat/lng pair?

Edited to add: I've been looking at the example on this page but cant seem to get it to work using PHP: http://www.movable-type.co.uk/scripts/latlong.html

1
I'm voting to close this question as off-topic because this has nothing to do with programming whatsoever.Daan
What do you mean it has nothing to do with programming? I am trying to automate some location targeting using PHPJay
No you'll have to do a calculation. So I'd suggest you'll ask it on mathematica.stackexchange.com. No programming at all involved here.Daan
From the page you've linked, Destination point given distance and bearing from start point and remember that you need to convert lat/lng and bearing to radians before executing the equation, and to convert lat/long back to degrees afterwards.... show your actual codeMark Baker
Thanks mark, I was actually forgetting to convert to radiansJay

1 Answers

0
votes

Here is my working code, takes a $lat/$lng and adds 75 miles EAST in this example.

        $distance = 75;
        $bearing = deg2rad(90);
        $lat1 = deg2rad($lat);
        $lng1 = deg2rad($lng);
        echo $lat1 . ', ' . $lng1;
        echo '<br>';
        $lat2 = asin(sin($lat1)*cos($distance/ 3959) + cos($lat1)*sin($distance/ 3959)*cos($bearing));
        $lng2 = $lng1 + atan2(sin($bearing)*sin($distance/3959)*cos($lat1), cos($distance/3959)-sin($lat1)*sin($lat2));
        echo rad2deg($lat2) . ', ' . rad2deg($lng2);