检查纬度和经度是否在圆圈内 [英] Check if a latitude and longitude is within a circle

查看:36
本文介绍了检查纬度和经度是否在圆圈内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看这个图:

我想知道的是:

  1. 如何在给定经纬度和距离(10 公里)的情况下创建区域(圆)
  2. 如何检查(计算)纬度和经度是在区域内还是区域外

我希望您能提供 Java 代码示例或专门针对带有 Google Maps API V2 的 Android 代码示例

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 two 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 对象:

If you have already Location objects:

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 the API used: https://developer.android.com/reference/android/location/Location.html

这篇关于检查纬度和经度是否在圆圈内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆