检查纬度和经度是否在圆圈内 [英] Check if a latitude and longitude is within a circle
本文介绍了检查纬度和经度是否在圆圈内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
参见此插图:
我想知道的是:
- 如何创建给定纬度和经度以及距离(10公里)时的区域(圆圈)
- 如何检查(计算)纬度和经度是否在区域内或区域外
如果你能用Java或者专门针对Android的Google Maps API V2给我代码示例我会更喜欢
I would prefer if you can give me code example in Java or specifically for Android with Google Maps API V2
推荐答案
你基本上需要的是地图上各点之间的距离:
What you basically need, is the distance between to points on the map:
float[] results = new float[1];
Location.distanceBetween(centerLatitude, centerLongitude, testLatitude, testLongitude, results);
float distanceInMeters = results[0];
boolean isWithin10km = distanceInMeters < 10000;
如果您已经位置
对象:
Location center;
Location test;
float distanceInMeters = center.distanceTo(test);
boolean isWithin10km = distanceInMeters < 10000;
以下是该API的有趣部分:
https://developer.android.com/reference/android/location/Location.html
Here is the interesting part of that API: https://developer.android.com/reference/android/location/Location.html
这篇关于检查纬度和经度是否在圆圈内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文