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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog