r08y
r08y

Reputation: 125

Drawing a circle on google maps static link

i'm trying to draw a circle on a static map by feeding getCircleAsPolyline with Location data and then encode with PolyUtil.encode, according to this SO answer https://stackoverflow.com/a/38100481/1520234.

unfortunately the output is not a circle but something strange like this:

output

can anybody kindly explain me why this happen and if it's possible to get a real circle and if so how?

thanks

EDIT

i apologize for not being very clear, i forgot to mention that actually my getCircleAsPolyline is slightly different from the one i linked since i used SphericalUtil.computeOffset to calculate the coordinates; anyway below is my getCircleAsPolyline function:

private static ArrayList<LatLng> getCircleAsPolyline(Location center, float radius) {
    ArrayList<LatLng> circlePath = new ArrayList<>();
    double step = 5.0;
    double centerLatitude = center.getLatitude();
    double centerLongitude = center.getLongitude();
    for (double angle = 0.0; angle < 360.0; angle += step) {
        LatLng circlePoint = SphericalUtil.computeOffset(
                new LatLng(centerLatitude, centerLongitude),
                radius,
                (90.0 - angle + 360.0) % 360.0
        );
        circlePath.add(circlePoint);
    }
    return circlePath;
}

but result is the one showed in picture

Upvotes: 0

Views: 804

Answers (1)

r08y
r08y

Reputation: 125

For those who'll come here having the same problem, well I simply got it avoiding to encode the polyline: infact as long as I drop PolyUtil.encode and append points as | lat, long | I've been able to draw a perfect circle.

Upvotes: 1

Related Questions