What is the conversion of latitude / longitude to 1 mile

I work with Google Maps and I need to be able to search within a radius of 5 miles around the center of the zip code, so I decided that the easiest way to do this is to compute the conversion of latitude / longitude to miles.

+7
source share
2 answers

Here is a basic idea using the Google Geometry library .

Remember to add a geometry library. It is separate from the Google map library.

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false"> </script> 

usage example:

  //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.

+7
source

Google is your friend. This was discovered in the first few results of "converting longitude to longitude miles": http://www.movable-type.co.uk/scripts/latlong.html

It even gives some javascript code. Just a note, it gives the result in KM, but it can easily be converted to miles.

+3
source

All Articles