I'm working with Google Maps and I need to be able to search in a 5 mile radius around a zip code center so I figured the easiest way to do that would be to figure out the conversion of latitude/longitude to miles.
One degree of latitude equals approximately 364,000 feet (69 miles), one minute equals 6,068 feet (1.15 miles), and one-second equals 101 feet. One-degree of longitude equals 288,200 feet (54.6 miles), one minute equals 4,800 feet (0.91 mile), and one second equals 80 feet.
One degree of latitude is divided into 60 minutes ('). One minute of latitude equals one nautical mile , which is equal to 1.15 land miles (1.85 km).
Each degree of latitude is approximately 69 miles (111 kilometers) apart. The range varies (due to the earth's slightly ellipsoid shape) from 68.703 miles (110.567 km) at the equator to 69.407 (111.699 km) at the poles. This is convenient because each minute (1/60th of a degree) is approximately one [nautical] mile.
The number of degrees of longitude covered if we circumnavigated Earth around the Equator would therefore be 360. However, unlike latitude, lines of longitude converge at the poles, which means that the length of a degree of longitude is not constant. At the Equator, it will be 69.4 miles, just like latitude.
Here is the basic idea using Google's Geometry library.
Remember to add the geometry library. It is separate than the Google maps library.
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false">
</script>
example usage:
//the distance function defaults to km.
//to use miles add the radius of the earth in miles as the 3rd param.
//earths radius in miles == 3956.6
var distance =
google.maps.geometry.spherical.computeDistanceBetween(
/* from LatLng */,
/* to LatLng */,
/* radius of the earth */
);
if (distance <= 5) { //less or equal to five miles
var marker = new google.maps.Marker({
map: map,
position: //LatLng
});
}
I have an example fiddle of this in action.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With