【问题标题】:GroundOverlay made with a Canvas in Google Maps Android API v2在 Google Maps Android API v2 中使用 Canvas 制作的 GroundOverlay
【发布时间】:2013-12-05 17:59:51
【问题描述】:
我也在尝试绘制弧线(我在 this 和 this 问题上引用)。我将从以下网络服务获取:
- 经纬度
- 半径(米)
- 开始角度(结束角度为 startA + 60 度)
现在我遇到以下问题,因为我没有两个 LatLng,只有一个,并且在新地图 api v2 中没有提供给 RectF.set(point.x - radius,.. .)
你有代码示例、链接等吗?
App 的性能怎么样,因为我在地图上最多可以有 500 条弧线?
【问题讨论】:
标签:
android
android-maps-v2
【解决方案1】:
从一个 LatLng 点开始,您可以计算给定距离(半径)和给定角度的另一个 LatLng 点,如下所示:
private static final double EARTHRADIUS = 6366198;
/**
* Move a LatLng-Point into a given distance and a given angle (0-360,
* 0=North).
*/
public static LatLng moveByDistance(LatLng startGp, double distance,
double angle) {
/*
* Calculate the part going to north and the part going to east.
*/
double arc = Math.toRadians(angle);
double toNorth = distance * Math.cos(arc);
double toEast = distance * Math.sin(arc);
double lonDiff = meterToLongitude(toEast, startGp.latitude);
double latDiff = meterToLatitude(toNorth);
return new LatLng(startGp.latitude + latDiff, startGp.longitude
+ lonDiff);
}
private static double meterToLongitude(double meterToEast, double latitude) {
double latArc = Math.toRadians(latitude);
double radius = Math.cos(latArc) * EARTHRADIUS;
double rad = meterToEast / radius;
double degrees = Math.toDegrees(rad);
return degrees;
}
private static double meterToLatitude(double meterToNorth) {
double rad = meterToNorth / EARTHRADIUS;
double degrees = Math.toDegrees(rad);
return degrees;
}