You can find the nearest city using the Haversine formula. The following functions are used to calculate the distance between geolocation coordinates and your array data.
function deg2rad(degrees){ radians = degrees * (Math.PI/180); return radians; } function Haversine(lat1,lon1,lat2,lon2) { deltaLat = lat2 - lat1 ; deltaLon = lon2 - lon1 ; earthRadius = 3959;
source share