-1

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.

Mohit Suthar
  • 8,725
  • 10
  • 37
  • 67
  • In the answer of the question you posted, you can clearly see the latitude and longitude of the various points of the circle in **step 2** – Greggz Sep 13 '18 at 13:40
  • I think SphericalUtil.computeOffset(from,distance,heading) is what you want - given circle center (from), circle radius (distance) and heading of your choosing you can then add marker at position returned. See - https://github.com/googlemaps/android-maps-utils. –  Sep 13 '18 at 15:47
  • @Andy thanks for your comment let me check with it – Mohit Suthar Sep 14 '18 at 05:00
  • @Greggz In step 2 given lat long is very different – Mohit Suthar Sep 14 '18 at 05:00

2 Answers2

2

@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));
}
Ankit Dubariya
  • 905
  • 2
  • 9
  • 22
0

Add the following code in onMapReady() method:

enter image description here

Mirza Adil
  • 352
  • 5
  • 9