Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9155127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:32:23+00:00 2026-06-17T12:32:23+00:00

Having the following code to draw circle (taken from Google Play Services maps sample):

  • 0

Having the following code to draw circle (taken from Google Play Services “maps” sample):

    PolylineOptions options = new PolylineOptions();
    int radius = 5; //What is that?
    int numPoints = 100;
    double phase = 2 * Math.PI / numPoints;
    for (int i = 0; i <= numPoints; i++) {
        options.add(new LatLng(SYDNEY.latitude + radius * Math.sin(i * phase),
                SYDNEY.longitude + radius * Math.cos(i * phase)));
    }
    int color = Color.RED;
    mMap.addPolyline(options
            .color(color)
            .width(2));

This is what gets drawn on different part of the world:

Sydney
Scandic

As you see circles are not really circles and even second one is ellipse basically.

I guess that “anti-aliasing” of circle depending on number of points in int numPoints variable.

  1. What is int radius = 5 variable in example code? I mean what measure it is?
  2. And main question what would be correct way of drawing nice circle with given radius in meters? Something smiliar to what we had in api v1 with canvas.drawCircle()

UPDATE ——————–

OK after improving math I was able to draw “right” circle:

private void addCircle(LatLng latLng, double radius)
    {
        double R = 6371d; // earth's mean radius in km
        double d = radius/R; //radius given in km
        double lat1 = Math.toRadians(latLng.latitude);
        double lon1 = Math.toRadians(latLng.longitude);         
        PolylineOptions options = new PolylineOptions();
        for (int x = 0; x <= 360; x++)
        {                      
            double brng = Math.toRadians(x);
            double latitudeRad = Math.asin(Math.sin(lat1)*Math.cos(d) + Math.cos(lat1)*Math.sin(d)*Math.cos(brng));
            double longitudeRad = (lon1 + Math.atan2(Math.sin(brng)*Math.sin(d)*Math.cos(lat1), Math.cos(d)-Math.sin(lat1)*Math.sin(latitudeRad)));             
            options.add(new LatLng(Math.toDegrees(latitudeRad), Math.toDegrees(longitudeRad)));
        }           
        mMap.addPolyline(options.color(Color.BLACK).width(2));          
    }

However anti-aliasing of circle I guess is somewhat beyond control, and on some zoom levels circle might get ugly:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:32:23+00:00Added an answer on June 17, 2026 at 12:32 pm

    How to draw circle in Google Maps v2 (bitmap)

    // 1. some variables:
    
        private static final double EARTH_RADIUS = 6378100.0;
        private int offset;
    
    // 2. convert meters to pixels between 2 points in current zoom:
    
        private int convertMetersToPixels(double lat, double lng, double radiusInMeters) {
    
             double lat1 = radiusInMeters / EARTH_RADIUS;
             double lng1 = radiusInMeters / (EARTH_RADIUS * Math.cos((Math.PI * lat / 180)));
    
             double lat2 = lat + lat1 * 180 / Math.PI;
             double lng2 = lng + lng1 * 180 / Math.PI; 
    
             Point p1 = YourActivity.getMap().getProjection().toScreenLocation(new LatLng(lat, lng));
             Point p2 = YourActivity.getMap().getProjection().toScreenLocation(new LatLng(lat2, lng2));
    
             return Math.abs(p1.x - p2.x);
        }
    
    // 3. bitmap creation:
    
        private Bitmap getBitmap() {
    
            // fill color
            Paint paint1 = new Paint(Paint.ANTI_ALIAS_FLAG);
            paint1.setColor(0x110000FF);
            paint1.setStyle(Style.FILL);
    
            // stroke color
            Paint paint2 = new Paint(Paint.ANTI_ALIAS_FLAG);
            paint2.setColor(0xFF0000FF);
            paint2.setStyle(Style.STROKE);
    
            // icon
            Bitmap icon = BitmapFactory.decodeResource(YourActivity.getResources(), R.drawable.blue);
    
            // circle radius - 200 meters
            int radius = offset = convertMetersToPixels(lat, lng, 200);
    
            // if zoom too small
            if (radius < icon.getWidth() / 2) {
    
                radius = icon.getWidth() / 2;
            }
    
            // create empty bitmap 
            Bitmap b = Bitmap.createBitmap(radius * 2, radius * 2, Config.ARGB_8888);
            Canvas c = new Canvas(b);
    
            // draw blue area if area > icon size
            if (radius != icon.getWidth() / 2) {
    
                c.drawCircle(radius, radius, radius, paint1);
                c.drawCircle(radius, radius, radius, paint2);
            }
    
            // draw icon
            c.drawBitmap(icon, radius - icon.getWidth() / 2, radius - icon.getHeight() / 2, new Paint());
    
            return b;
        }
    
    // 4. calculate image offset:
    
        private LatLng getCoords(double lat, double lng) {
    
            LatLng latLng = new LatLng(lat, lng);
    
            Projection proj = YourActivity.getMap().getProjection();
            Point p = proj.toScreenLocation(latLng);
            p.set(p.x, p.y + offset);
    
            return proj.fromScreenLocation(p);
        }
    
    // 5. draw:
    
            MarkerOptions options = new MarkerOptions();
                options.position(getCoords(lat, lng));
                options.icon(BitmapDescriptorFactory.fromBitmap(getBitmap()));
    
                marker = YourActivity.getMap().addMarker(options);
    

    and result:

    google maps v2 draw circle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having following code for getting image from the web: NSURL *ImageURL =
Having the following code at hand: ExecutorService executor = Executors.newFixedThreadPool(10); Collection collection = new
Having the following code: switch ($options['algorythm']) { case 'jigsaw': $result = $this->jigsaw($options['count'], $options['length']); break;
I am having following code but unable to understand as to why no match
I am having the following code: public ActionResult EditTrain(EditTraing editrain) { .... .... return
I m having the following code, however, I can see that the radio button
I am having following peice of code ,where in i am trying to serialize
I'm having problems the following code gives me no results. however if I uncomment
Just wondering, having the following simple code: var object1 = { name: function (){
The following code is having some problem with the jQuery. <script type="text/javascript"> $(window).load(function() {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.