GroundOverlay made with a Canvas in Google Maps Android API v2

六月ゝ 毕业季﹏ 提交于 2019-12-29 08:22:18

问题


I'm also try to draw arc (I'm referencing on this and this questions). I'll get from web service following:

  • Lat and Lng
  • Radius (in meters)
  • Start angle (end angle is startA + 60 degrees)

Now I encounter on following problem because I do not have two LatLng, just one, and in new map api v2 there is no radius = Projection.metersToEquatorPixels method for providing to RectF.set(point.x - radius,...)

Do you have code example, links, etc?

Also what about performances of App, because I'll have up to 500 arcs on map?


回答1:


Starting from a LatLng point you can calculate another LatLng point in a given distance (radius) and a given angle as follows:

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;
}


来源:https://stackoverflow.com/questions/20407310/groundoverlay-made-with-a-canvas-in-google-maps-android-api-v2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!