dqmhgz5848 2015-07-07 11:50
浏览 81
已采纳

如何在纬度和经度的帮助下找到30公里范围内的位置[关闭]

I have lot of stores in my database table with their locations (lat and long). Now my requirement is to fetch the all the stores which are in the range of say 30 km.

Please see the image of table below. I have also attached MySQL file of the same.

store_id store_name                               lat       lng
     416 Modissa                                  47.374757 8.538985
     916 A.C. Bang Pelze                          47.367312 8.540046
     917 Arbijoux                                 47.367312 8.540046
     918 VP Bank (Schweiz) AG at Bahnhofstrasse 3 47.367537 8.539934
     919 Pelzparadies Wyssbrod                    47.367537 8.539934
     920 ZKB                                      47.36895  8.542147
     921 Weinbeg Damenmode                        47.368943 8.539316
     922 Kochoptik                                47,368564 6.539617
     923 Nouvelle Boutique                        47.368639 8.539533
     924 Trois Pommes                             47.369897 8.540631
     925 Lords of Sweden                          47.205619 8.422326
     926 Weinberg Herrenmode                      47.368943 8.539316
     927 Dior                                     47.305422 8.899034
     928 Stefano Ricci                            47.371972 8.5386
     929 Villa Grisebach Auktionen                47.368505 8.539898
  • 写回答

3条回答 默认 最新

  • doujie9882 2015-07-07 12:01
    关注

    If you do not need a real precise (but fast!) result, you could try the following:

    • You have a given lat/lng of a place to search around
    • Draw a rectangle around with that place in the middle
    • Search in the database if your stores fit within the range

    1.00 lat = ~110.54 km

    1.00 lng = ~(111.32 * cos(deg2rad($lat)))

    With that given, you may calculate your min/max lat/lng for the rectangle. To be more precise, here's my code for that:

    $radiusLat = 30 / 110.54;
    $radiusLng = 30 / (111.32 * cos(deg2rad($lat)));
    $latMin = $lat - $radiusLat;
    $latMax = $lat + $radiusLat;
    $lngMin = $lng - $radiusLng;
    $lngMax = $lng + $radiusLng;
    $sqlWhere =  "(lat >= '{$latMin}' AND lat <= '{$latMax}' AND lng >= '{$lngMin}' AND lng <= '{$lngMax}')";
    

    P.S.: Do not forget to set an index to lat and lng columns.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错