Sort list of lonlat points, start with nearest(对 lonlat 点的排序列表,从最近的开始)
问题描述
我有来自 GPS 的位置(lon_base、lat_base).我有一个位置列表(lon1、lat1|lon2、lat2|lon3、lat3...)这个列表很长,遍布世界各地.
I have location from GPS (lon_base, lat_base). I have a list of locations (lon1, lat1|lon2, lat2|lon3, lat3...) This list is very long and is around the world.
我的问题是:1. 如何从该列表中仅获取距离我的 lon_baselat_base 1 英里的 lonlat?2. 如何从近到远排序?
My questions are: 1. How do I get from that list only the lonlat that are 1 mile from my lon_baselat_base? 2. How do I sort them from closest to farthest?
提前致谢!
推荐答案
你想定义你自己的 Comparator,一般看起来像这样:
You want to define your own Comparator that, in general, looks something like this:
LonLat myHouse = /* whatever */ ;
Comparable comp = new Comparable () {
LonLat a;
int compareTo (Object b) {
int aDist = calcDistance(a, myHouse) ;
int bDist = calcDistance(b, myHouse) ;
return aDist - bDist;
}
};
myLonLatList.sort(lonLatList, comp);
其中 calcDistance() 只是计算两点之间的距离.如果您使用的是 Android,我认为 Google Maps 在其 API 中的某处有一个功能可以为您执行此操作.
where calcDistance() simply calculates the distance between the two points. If you're on Android, I think Google Maps has a function somewhere in their API that will do this for you.
EDIT:你会希望你的 calcDistance() 函数看起来像 ChrisJ 的 distance 函数.
EDIT : You'll want your calcDistance() function to look like ChrisJ's distance function.
-tjw
这篇关于对 lonlat 点的排序列表,从最近的开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:对 lonlat 点的排序列表,从最近的开始
基础教程推荐
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
