基本上,标题说明了一切。而不是地图,因为我目前做我的数据库中的每一个条目阴谋,我想查询数据库,只有绘制其坐标落在围绕用户当前的位置绘制的圆内的项目,但我不能完全弄清楚如何做到这一点。目前,我写了与存储在我的数据库中的所有条目的位置,并围绕当前位置的圆沿绘制地图上的用户当前位置的代码(见下图)。基于下面我的照片,我只是想在圆内的3个标记进行绘制。
有谁知道,如果有检查,如果存储在我的数据库秋天的圆面积内的经纬度坐标的任何方式?或者,如果没有,任何人都可以表明,使用了类似的想法任何替代品。
另一种我在想的是使用正方形/长方形而不是圆形,这样我可以简单地用正方形/长方形范围比较我的条目的坐标,但是我真的不知道如何可行的,被视为这些形状不是由谷歌地图API的支持。我也遇到了LatLngBounds类可能是有用的,但使用它,我无法找到任何的示例代码。我怎么可能会做这一点?
我相信圆具有固定半径和中心点。
所以,去用这种方法得到的中心和一些经纬度之间的距离,设置条件
距离<=半径
public static String getDistance(LatLng ll_source, LatLng ll_destination,
int unit) {
int Radius = 6371;// radius of earth in Km
double lat1 = ll_source.latitude;
double lat2 = ll_destination.latitude;
double lon1 = ll_source.longitude;
double lon2 = ll_destination.longitude;
double dLat = Math.toRadians(lat2 - lat1);
double dLon = Math.toRadians(lon2 - lon1);
double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
+ Math.cos(Math.toRadians(lat1))
* Math.cos(Math.toRadians(lat2)) * Math.sin(dLon / 2)
* Math.sin(dLon / 2);
double c = 2 * Math.asin(Math.sqrt(a));
double valueResult = Radius * c;
double km = valueResult / 1;
DecimalFormat newFormat = new DecimalFormat("####");
Integer kmInDec = Integer.valueOf(newFormat.format(km));
double meter = valueResult % 1000;
Integer meterInDec = Integer.valueOf(newFormat.format(meter));
DecimalFormat df = new DecimalFormat("#.#");
return df.format(valueResult);
}
好吧,我已经想通了使用的LatLngBounds类我在问题中提及的解决方案。它的作用是:
public void getNearbyMarkers(){
LatLngBounds perimeter = new LatLngBounds(new LatLng(currentLat - 0.004,
currentLon - 0.004), new LatLng(currentLat + 0.004, currentLon + 0.004));
if (perimeter.contains(LatlongFromDatabase)) {
//Plot Marker on Map
} else {
Toast.makeText(getApplicationContext(), "Co-ordinates not in perimeter!", 8).show();
}
}