GroundOverlay made with a Canvas in Google Maps Android API v2
Asked Answered
K

1

0

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?

Kofu answered 5/12, 2013 at 17:59 Comment(0)
S
2

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;
}
Spagyric answered 5/12, 2013 at 19:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.