KPRF2009 2012-12-11 00:53 采纳率: 50%
浏览 5343
已采纳

android 求区域内坐标(经纬度)的问题。。。

android 已知有N个坐标(经纬度),现在求坐标(x,y(经纬度))在半径不超过X米并且在N个坐标(经纬度)中有那些坐标(经纬度)点???

我问这个问题有2个点想知道

  1. 2个坐标(经纬度)怎么求距离

  2. 难道每次求,都要遍历N个坐标算一次距离吗?

  • 写回答

2条回答 默认 最新

  • Hooopo 2012-12-11 02:47
    关注

    求两个坐标之间距离

    Location对象带和距离相关的方法,求两个坐标距离: public static void distanceBetween (double startLatitude, double startLongitude, double endLatitude, double endLongitude, float[] results)

    Parameters
    startLatitude   the starting latitude
    startLongitude  the starting longitude
    endLatitude the ending latitude
    endLongitude    the ending longitude
    results an array of floats to hold the results
    

    详细解释见这里: distanceBetween(double, double, double, double, float[])

    在大量坐标之间找最近距离的坐标

    如果你用Mongodb,获取最近的坐标很简单,Mongodb自带geoNearCommand,可以参照这里:GeospatialIndexing-geoNearCommand

    > db.runCommand( { geoNear : "places" , near : [50,50], num : 10 } );
    > db.runCommand({geoNear:"asdf", near:[50,50]})
    {
            "ns" : "test.places",
            "near" : "1100110000001111110000001111110000001111110000001111",
            "results" : [
                    {
                            "dis" : 69.29646421910687,
                            "obj" : {
                                    "_id" : ObjectId("4b8bd6b93b83c574d8760280"),
                                    "y" : [
                                            1,
                                            1
                                    ],
                                    "category" : "Coffee"
                            }
                    },
                    {
                            "dis" : 69.29646421910687,
                            "obj" : {
                                    "_id" : ObjectId("4b8bd6b03b83c574d876027f"),
                                    "y" : [
                                            1,
                                            1
                                    ]
                            }
                    }
            ],
            "stats" : {
                    "time" : 0,
                    "btreelocs" : 1,
                    "btreelocs" : 1,
                    "nscanned" : 2,
                    "nscanned" : 2,
                    "objectsLoaded" : 2,
                    "objectsLoaded" : 2,
                    "avgDistance" : 69.29646421910687
            },
            "ok" : 1
    }
    

    PS. 这里有很多计算GEO距离相关的公式:http://www.movable-type.co.uk/scripts/latlong.html

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

报告相同问题?

悬赏问题

  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问