dongtu1789 2011-12-22 13:02
浏览 82

最近的纬度和经度位置

I just have latitude and longitude of a store, now I want to find out all the stores near by in 1 hour drive or say at 10 KM distance.

I have table as,

Id, storeName, store_lat, store_lng

Say I have selected lat and lng of store 1 and I want to find out all the nearby stores. How to do that using php/mysql.

I have checked many post on SO but when I am running query, it's returning 0 results all the time.

Please help, thanks!

  • 写回答

4条回答 默认 最新

  • dongliu4320 2011-12-22 13:13
    关注

    One approach is to take your input lat/long pair, create a range, then query for all records that fall in that range:

    Distance = 0.1; // Range in degrees (0.1 degrees is close to 11km)
    LatN = lat + Distance;
    LatS = lat - Distance;
    LonE = lon + Distance;
    LonW = lon - Distance;
    
    ...Query DB with something like the following:
    SELECT *
    FROM table_name
    WHERE 
    (store_lat BETWEEN LatN AND LatS) AND
    (store_lon BETWEEN LonE AND LonW)
    

    The query should find everything where the stored lat is less than LatN and greater than LatS, and where the stored lon is less than LonE and greater than LonW.

    You might then do a real distance calcuation for the returned results because the above search gives you a box, and locations in the corner will be greater than 0.1 degrees away, as the crow flies.

    Use a map API with directions to get the driving distance, if "as the crow flies" isn't good enough.

    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行