【发布时间】:2015-11-28 21:38:34
【问题描述】:
我正在尝试在给定位置附近的地图上生成随机点。我有一个circle 形状,它围绕半径为 100 的用户位置,我想在这个圆形区域内生成随机 LatLng 坐标。到目前为止我已经想出了以下功能,但是点标记仍然出现在圆圈范围之外。
double lat = location.getLatitude();
double lon = location.getLongitude();
for (int i = 0; i < markers.size(); i++) {
Marker mrk = markers.get(i);
Random random = new Random();
double radiusInDegrees =mCircle.getRadius();
double u = random.nextDouble();
double v = random.nextDouble();
double w = radiusInDegrees * Math.sqrt(u);
double t = 2 * Math.PI * v;
double x = w * Math.cos(t);
double y = w * Math.sin(t);
// Adjust the x-coordinate for the shrinking of the east-west distances
double new_x = x / Math.cos(lat);
double newLongitude = new_x + lon;
double newLatitude = y + lat;
mrk.setPosition(new LatLng(newLatitude,newLongitude));
}
【问题讨论】:
标签: android google-maps android-maps-v2