I'm attempting to find the longitude (east-west) angle of a new point given that latitude does not also change.
Given: Starting Latitude, Starting Longitude, distance of travel in miles.
Desired result: Maximum and Minimum Longitude and Latitude degrees that are "distance of travel" from starting point.
Code below:
Attempt 1: Use "close enough" constants:
function(longitude, latitude, travelRadius, next){
var milesPerDegreeOfLongitude = 69.172;
var milesPerDegreeOfLatitude = 69.2;
var location = { longitude : longitude, latitude : latitude };
var longitudeDelta = (travelRadius / milesPerDegreeOfLongitude);
location.maxLongitude = longitude + longitudeDelta;
location.minLongitude = longitude - longitudeDelta;
var latitudeDelta = (travelRadius / milesPerDegreeOfLatitude);
location.maxLatitude = latitude + latitudeDelta;
location.minLatiude = latitude - latitudeDelta;
next(location);
}
^ This yields very close latitude, for a distance of 5 miles. But longitude for the same is about 3.93 miles as measured by google maps, too high of a variance.
Attempt 2: One radian is the angle for a line 3,958.761 miles long (the Earth's radius) therefore the angle for a line X miles long is X/3,958.761 radians.
function(longitude, latitude, travelRadius, next){
var radiusOfEarth = 3959.761;
//... omitting latitude ...
var distanceInRadians = (travelRadius / radiusOfEarth);
var degrees = (180 / Math.PI) * distanceInRadians;
location.maxLongitude = longitude + degrees;
location.minLongitude = longitude - degrees;
next(location)
}
^ And again I end up with about 3.93 miles on longitude distance. What could I do to get this right or at least within .5 miles of error?
Edit: attempt 3 using Mbo's suggestion:
var latitude = 37.7118042;
var longitude = -122.4458397;
var travelradius = 5;
function(latitude, longitude, travelRadius){
var milesPerDegreeOfLatitude = 69.172;
var milesPerDegreeOfLongitude = 69.172 * Math.cos(latitude)
var location = { longitude : longitude, latitude : latitude };
var latitudeDelta = (travelRadius / milesPerDegreeOfLatitude);
location.maxLatitude = latitude + latitudeDelta;
location.minLatiude = latitude - latitudeDelta;
var longitudeDelta = (travelRadius / milesPerDegreeOfLongitude);
location.maxLongitude = longitude + longitudeDelta;
location.minLongitude = longitude - longitudeDelta;
return location;
}
Outputs:
{
longitude: -122.4458397,
latitude: 37.7118042,
maxLongitude: -122.37355611704736,
minLongitude: -122.51812328295263,
maxLatitude: 37.784058535260115,
minLatiude: 37.63954986473989
}
Where Max longitude is ~3.85 miles from starting position. Still off, expecting something like: -122.3515 which is ~5 miles