如何通过距离过滤网站上的位置


How to filter locations on website by distance between

我有测试网站,其中列出了带有gps坐标的餐厅。我想只过滤和显示在我的位置附近的项目。有人能帮我吗?

只要你知道你的gps坐标,那么

function distance(myloc, restloc) {
    x_dist = myloc.x - restloc.x;
    y_dist = myloc.y - restloc.y;
    return sqrt(x_dist*x_dist + y_dist*y_dist);

然后可以按距离进行过滤。