MySQL PHP zip code comparison specifically distance

后端 未结 1 1732
既然无缘
既然无缘 2021-01-07 15:01

I\'m trying to figure out what would be the most efficient (with respect to load time) to compare the distance between one zip code (which the user provides) and a whole bun

相关标签:
1条回答
  • 2021-01-07 15:17

    In Javascript:

    var R = 6371; // km
    var dLat = (lat2-lat1).toRad();
    var dLon = (lon2-lon1).toRad(); 
    var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
            Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) * 
            Math.sin(dLon/2) * Math.sin(dLon/2); 
    var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
    var d = R * c;
    

    where d = distance between two points

    This is the Haversine formula.

    0 讨论(0)
提交回复
热议问题