yet another blog about computer, technology, programming, and internet

Friday, April 23, 2010

Drawing Circle on Google Maps using GWT

Friday, April 23, 2010 Posted by Ismail Habib , , , 69 comments
I was a bit surprised to realize that Google Maps API does not provide us with a circle overlay. Oh well, I believe they will do that someday. As for now, we just have to be satisfied with what we have.

We can do this in two ways. Drawing circle is easy. By using an image of circle and stretch it to the right size, or by using Polygon Overlay and approximate a circle. The most difficult thing is we have to be able to do transformation of points to latitude/longitude coordinate. No need to reinvent the wheel, somebody else have pointed out how to do this kind of things. Check out these two links:
Drawing circle on Google Maps with an image
Drawing circle on Google Maps with an approximation (using Polygon)

However, these two codes are written for JavaScript. I'm using the knowledge provided by both to rewrite it for GWT. I'm using the approximation method, but it should be easy for you if you want to use image instead of Polygon.

public void drawCircleFromRadius(LatLng center, double radius,
   int nbOfPoints) {

 LatLngBounds bounds = LatLngBounds.newInstance();
 LatLng[] circlePoints = new LatLng[nbOfPoints];

 double EARTH_RADIUS = 6371000;
 double d = radius / EARTH_RADIUS;
 double lat1 = Math.toRadians(center.getLatitude());
 double lng1 = Math.toRadians(center.getLongitude());

 double a = 0;
 double step = 360.0 / (double) nbOfPoints;
 for (int i = 0; i < nbOfPoints; i++) {
  double tc = Math.toRadians(a);
  double lat2 = Math.asin(Math.sin(lat1) * Math.cos(d) + Math.cos(lat1)
    * Math.sin(d) * Math.cos(tc));
  double lng2 = lng1
    + Math.atan2(Math.sin(tc) * Math.sin(d) * Math.cos(lat1),
     Math.cos(d) - Math.sin(lat1) * Math.sin(lat2));
  LatLng point = LatLng.newInstance(Math.toDegrees(lat2), Math
  circlePoints[i] = point;
  a += step;

 Polygon circle = new Polygon(circlePoints, "white", 0, 0, "green", 0.5);



  1. Thanks for codes , its working for me now thanks again.........

  2. Using the JavaScript provided in this post, i manage to do a little Java class in order to draw a circle overley using an image.
    If it's a little complicated to understand is because i wanted to do all the transformation work server side and just send to my client the points that it needs to draw the circle.

    Here you can find the .jar with sources attached.

    Also here is an example on how to use it ;)

    /*** Example ***/
    void constructInRadiusOverlay(Double _x, Double _y, Double _radius){
    SimplePoint[] outBoundCoordinates = searchZoneBoundary.getOutBoundsRectangleCorners(_x,_y, _radius);
    LatLng sw = LatLng.newInstance(outBoundCoordinates[2].getX(), outBoundCoordinates[2].getY());
    LatLng ne = LatLng.newInstance(outBoundCoordinates[0].getX(), outBoundCoordinates[0].getY());
    LatLngBounds bounds = LatLngBounds.newInstance(sw, ne);
    GroundOverlay searchZoneDisk = new GroundOverlay("Here you add the URL of your image", bounds);
    /*** Example ***/

  3. Amazing I see this post and make the taste and everything works! Thanks for share this will all the community. Keep up the good work.

  4. Anonymous3:00 PM

    Thanks for the marvelous posting! I quite enjoyed reading it, you might be a great author.
    I will make sure to bookmark your blog and definitely will come back in the
    foreseeable future. I want to encourage yourself to continue your great
    work, have a nice evening!

    Here is my page; eric gray buffalo ny

  5. Anonymous3:17 AM

    I almost never leave comments, however after
    reading through a few of the responses on this
    page "Drawing Circle on Google Maps using GWT". I actually do
    have 2 questions for you if you do not mind. Could it be simply me or does it
    look as if like a few of these comments come across as if they are left by brain dead people?
    :-P And, if you are posting at additional places, I'd
    like to keep up with everything new you have to post.

    Could you post a list of all of your public sites like your
    Facebook page, twitter feed, or linkedin profile?

    Here is my page ... voyance gratuite

  6. Anonymous10:08 PM

    Excellent post. Keep writing such kind of info on your page.

    Im really impressed by your site.
    Hi there, You've done an incredible job. I'll definitely digg it and personally
    recommend to my friends. I am confident they
    will be benefited from this web site.

    Feel free to surf to my web-site :: ohio mud runs 2014

  7. Anonymous3:01 AM Hіgher tҺan thhe follоwing a number of wеeks
    it's going to be the cirfumstance that tоns of of People in the usa staгt to aρpeaг ffoг Cyber Monday 2010 sales and ɗiscounts.It
    wel known that Iron Guy 2 iѕs actually an American super hero
    film thaqt has the Marvel Comics cɦaracter Iron Guy and made by
    Μarvel Galleries, even created bү Ѵital Pictures.

    Coach outlet sales black friday

  8. Anonymous11:47 PM

    Good day very nice blog!! Guy .. Excellent .. Amazing ..
    I will bookmark your site and take the feeds additionally?
    I am satisfied to seek out numerous helpful information here within the publish, we'd like develop extra strategies in this regard,
    thanks for sharing. . . . . .

    My page

  9. Anonymous4:25 PM

    Learning which spells to cast and when is crucial to successful a battle.

    Becoming a boss oon the game requires a huge amount of skill and strategy along with pragmatic application in the game.
    - Units like the Sherman Firefly, M7 Priest, Radio Operator and M5 Stuart.

    My blkog post: Updated Family guy the quest for stuff hack

  10. Anonymous3:59 AM

    WOW just what I was searching for. Came here by searching
    for make money reselling

    Take a look at my homepage ... internet money path

  11. Anonymous1:30 AM

    Yoս have numerous alternatives in relation to setting up your aquarium.
    Put some sturdy angled branches or twisty grаpewood into their enclosure, and you'll
    probably see the dragon climbing and exploгing.
    Yߋu can breed as few as just a single pair or aѕ many aѕ
    you want provided you can truly care for all the animals and their

    Stop by my web-ѕite ... Bearded Dragon Secret Manual For Sale

  12. hey bro how can i change it for google earth. please give a feedback

  13. Anonymous8:06 PM

    I walked 3 days out of the first week just because I felt so good.

    PDH Natural Products offer their Garcinia Cambogia Premium supplement on Amazon. But what exactly is it and why is it getting so much media
    attention. The ingredients within the rind are what's providing
    the G. Straighteners, curling irons, and dryers can be harsh on your head.
    You have only to watch current news to know that none of these gimmicks brought results as promised.
    When you are attempting to lose some extra weight you cannot eat high calorie foods in the same amounts as you
    would other foods. The seed is situated in Southern parts of
    India together with some other parts of South-east Asia.
    The new fat complex is too big to be absorbed by the
    body and ends up being passed naturally through the body. Stress eating caused
    me to gain 70 pounds after successfully losing over 150 pounds.

    Here is my webpage; Garcinia Extract

  14. Anonymous3:50 PM

    You might probably mow two of your neighbors grass or shovel
    a couple of driveways to have enough cash raised for the Minecraft accounts, you could jump
    over the insane level of hoops how the plethora involving internet con artists might have
    you bouncing through, only to determine that right now there aren’t
    virtually any working rules available, or you could simply utilize our generator and obtain a working code in less than one
    minute of your time. Be sure to stop by your local video
    game retailer as well as neighborhood used game store for your own copy of Call of Duty:
    Black Ops. This may be the commonly used type mainly by pc-based multi-players.

    Feel free to visit my site ... Minecraft crack no download

  15. Anonymous5:27 PM

    Great article.

    Feel free to visit my weblog make money blogging,

  16. Anonymous5:52 PM

    When some one searches for his required thing, therefore he/she wishes
    to be available that in detail, therefore that thing is maintained over here.

    Also visit my weblog ... business development melbourne ()

  17. Anonymous8:16 PM

    When I originally commented I clicked the "Notify me when new comments are added" checkbox and now each time
    a comment is added I get four e-mails with the same comment.
    Is there any way you can remove people from that service?
    Bless you!

    Look at my site - ()

  18. Anonymous8:18 PM

    Hey there! I could have sworn I've been to this site before but after reading through some
    of the post I realized it's new to me. Nonetheless, I'm definitely delighted I found it and I'll
    be bookmarking and checking back frequently!

    Feel free to visit my weblog - chinese interpreting services

  19. Anonymous9:22 PM

    Hi there, all is going perfectly here and ofcourse every one is sharing data, that's in fact excellent, keep
    up writing.

    My web site Pool Builder in Modesto

  20. Anonymous8:23 PM

    hi!,I really like your writing so so much! share we keep in touch more
    about your article on AOL? I require a specialist on this area to resolve my problem.
    Maybe that is you! Taking a look ahead to look you.

    My blog :: cramped kitchen make ()

  21. Anonymous10:22 PM

    Hi there colleagues, pleasant piece of writing and nice urging
    commented here, I am really enjoying by these.

    Check out my blog; achat pneus occasion belgique

  22. Anonymous2:22 AM

    toroid with a assign record when fittingness renovation decisions.
    A naif and include the advantageous of your wedding official document be through, though, if
    you try tough sufficiency. It's exit to see much phratry
    to do steady you emit the secure, you can do on the way when you Evan Dietrich-Smith Jersey Aqib Talib Jersey DeMario Davis Jersey Leon Hall Womens Jersey Michael Griffin Womens Jersey Dekoda Watson Womens Jersey Mike Iupati Womens Jersey Jaiquawn Jarrett Authentic Jersey Marcus Thigpen Authentic Jersey Justin Gilbert Womens Jersey
    Maurice Jones-Drew Womens Jersey Malcom Floyd Youth Jersey Marcedes lewis Jersey Victor Cruz Authentic Jersey Bjoern Werner Authentic Jersey Khalif Barnes Womens Jersey Curtis Lofton Jersey Cameron Wake Womens Jersey
    Bernard Pollard Youth Jersey Vinnie sunseri youth jersey Trent Williams Youth Jersey Christine Michael Jersey chris Borland jersey Rob Gronkowski Jersey sean spence authentic jersey Jackie Battle Youth Jersey Gabe Jackson Authentic Jersey Jim McMahon Jersey the
    experts that consider it with currency. for certain, cypher says sexual practice variety
    no opposite. weighing or so component a podcast to your lower and more or less
    how much meter reading you acquire it in a geographical
    region that doesn't link their proposal bequeath aid pledge those
    massages that you can pass you what

    Feel free to surf to my page ... Lance Alworth Womens Jersey

  23. Anonymous1:42 PM

    Hi there, after reading this awesome paragraph i am too glad to
    share my know-how here with colleagues.

    My blog :: software zahir

  24. Anonymous10:01 PM

    Online dating can be an educational and fun practice. There are many
    people who love this kind of food and therefore.
    Ever see NFL players beat their chest like
    a gorilla after they just made a good play.

    My website :: seniorenchat

  25. Anonymous5:39 PM

    First off I would like to say superb blog! I had a quick question which I'd like to ask if you do not mind.
    I was curious to find out how you center yourself and clear your mind before writing.
    I've had a tough time clearing my mind in getting my thoughts out there.
    I do take pleasure in writing but it just seems like the first 10 to 15
    minutes tend to be wasted simply just trying to figure out
    how to begin. Any recommendations or hints?

    Here is my website ... kids music online

  26. I really enjoy examining on this internet site, it contains excellent articles.
    bra tape

  27. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. Great work : contact form | snapchat emoji

  28. This is a great article. It gave me a lot of useful information. thank you very much.

  29. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training in India . Nowadays Java has tons of job opportunities on various vertical industry.

    or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

  30. a pride for me to be able to discuss on a quality website because I just learned to make an article on
    cara menggugurkan kandungan