steampowered
steampowered

Reputation: 12062

Convert nautical miles to degrees longitude given a latitude using Google maps

I want to explicitly define a Google maps LatLngBounds object to be x nautical miles to the right of a LatLong P and x nautical miles left of P. And define the LatLngBounds to be y nautical miles above the point P and y nm below P.

So basically I want to define a LatLngBounds using latitude and longitude, and I want to get that latitude and longitude from x, y, and P.

Degrees latitude converts to degrees longitude easily: 1 degree equals one nautical mile. But
degrees longitude per nm changes with latitude. The formula is (in php)

public static function degPerNmAtLat($lat) {
    $pi80 = M_PI / 180;
    $lat = $lat*$pi80; //convert lat to radians
    $p1 = 111412.84;        // longitude calculation term 1
    $p2 = -93.5;            // longitude calculation term 2
    $p3 = 0.118;            // longitude calculation term 3
    // below: calculate the length of a degree of latitude and longitude in meters
    $longlen = ($p1 * cos($lat)) + ($p2 * cos(3 * $lat)) +  ($p3 * cos(5 * $lat));
    $longlen = $longlen * (3.280833333) / (5280 * 1.15077945);  // convert to nautical miles
    return 1/$longlen;
}

But this seems like a common task, and I wonder if Google maps has a function I am missing which would accomplish this. Is there a native Google maps way to create my LatLngBounds object from x, y, and P without using the formula above?

Upvotes: 4

Views: 3553

Answers (1)

John Black
John Black

Reputation: 621

You could use computeOffset() function in the Google Maps API V3 geometry library:

var dist = nauticalMiles * 1852; // convert nm to meters
var point = new google.maps.LatLng(lat,lng);
var eastPoint = google.maps.geometry.spherical.computeOffset(point,dist,90.0);
var westPoint = google.maps.geometry.spherical.computeOffset(point,dist,270.0);

Upvotes: 3

Related Questions