检查纬度和经度是否在圆圈内

Pet*_*rbo 17 java android area latitude-longitude google-maps-android-api-2

看这个插图:

在此输入图像描述

我想知道的是:

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

如果您能使用Google Maps API V2为我提供Java代码示例或专门针对Android的代码示例,我更愿意

flx*_*flx 28

你基本上需要的是地图上点之间的距离:

float[] results = new float[1];
Location.distanceBetween(centerLatitude, centerLongitude, testLatitude, testLongitude, results);
float distanceInMeters = results[0];
boolean isWithin10km = distanceInMeters < 10000;
Run Code Online (Sandbox Code Playgroud)

如果您已有Location对象:

Location center;
Location test;
float distanceInMeters = center.distanceTo(test);
boolean isWithin10km = distanceInMeters < 10000;
Run Code Online (Sandbox Code Playgroud)

以下是该API的有趣部分:https: //developer.android.com/reference/android/location/Location.html

  • 我有这个问题。它是包括到达某个位置的路径的距离还是仅两点之间的距离。 (2认同)