Google Map Android : Marker above Circle

↘锁芯ラ 提交于 2019-12-13 09:13:34

问题


I want to achieve like that in my application, I know about to draw a circle, but I need to show the marker in above right side of the circle in below image

I want to show 10Km above the circle if anyone knows about that plz help me.

I know about this question but kind find any solution.

If you know lat lng of the circle(outside edge) draw that also helpful for me.


回答1:


@Adny is right about that, I am also using SphericalUtil class to solve this type of problem,

You can use this SphericalUtil class from this git https://github.com/googlemaps/android-maps-utils

You can use this method to draw marker of 10Km

/**
 * Returns the location of origin when provided with a LatLng destination,
 * meters travelled and original heading. Headings are expressed in degrees
 * clockwise from North. This function returns null when no solution is
 * available.
 * @param to       The destination LatLng.
 * @param distance The distance travelled, in meters.
 * @param heading  The heading in degrees clockwise from north.
 */
public static LatLng computeOffsetOrigin(LatLng to, double distance, double heading) {
    heading = toRadians(heading);
    distance /= EARTH_RADIUS;
    // http://lists.maptools.org/pipermail/proj/2008-October/003939.html
    double n1 = cos(distance);
    double n2 = sin(distance) * cos(heading);
    double n3 = sin(distance) * sin(heading);
    double n4 = sin(toRadians(to.latitude));
    // There are two solutions for b. b = n2 * n4 +/- sqrt(), one solution results
    // in the latitude outside the [-90, 90] range. We first try one solution and
    // back off to the other if we are outside that range.
    double n12 = n1 * n1;
    double discriminant = n2 * n2 * n12 + n12 * n12 - n12 * n4 * n4;
    if (discriminant < 0) {
        // No real solution which would make sense in LatLng-space.
        return null;
    }
    double b = n2 * n4 + sqrt(discriminant);
    b /= n1 * n1 + n2 * n2;
    double a = (n4 - n2 * b) / n1;
    double fromLatRadians = atan2(a, b);
    if (fromLatRadians < -PI / 2 || fromLatRadians > PI / 2) {
        b = n2 * n4 - sqrt(discriminant);
        b /= n1 * n1 + n2 * n2;
        fromLatRadians = atan2(a, b);
    }
    if (fromLatRadians < -PI / 2 || fromLatRadians > PI / 2) {
        // No solution which would make sense in LatLng-space.
        return null;
    }
    double fromLngRadians = toRadians(to.longitude) -
            atan2(n3, n1 * cos(fromLatRadians) - n2 * sin(fromLatRadians));
    return new LatLng(toDegrees(fromLatRadians), toDegrees(fromLngRadians));
}



回答2:


Add the following code in onMapReady() method:



来源:https://stackoverflow.com/questions/52314634/google-map-android-marker-above-circle

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