对 lonlat 点的排序列表,从最近的开始

Sort list of lonlat points, start with nearest(对 lonlat 点的排序列表,从最近的开始)
本文介绍了对 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 点的排序列表,从最近的开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)