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

Thursday, February 03, 2011

GWT and Delayed Execution for Google Maps Geocoding

Thursday, February 03, 2011 Posted by Ismail Habib , 58 comments
Google Maps provide us with an asynchronous way of doing a geocoding, which is pretty much how GWT is dealing with all type of client-server communication. However, sometimes we need a way to synchronize them. By synchronizing I mean waiting for the required asynchronous call to return a value before continue with other execution. Using something like Timer to wait for a reply doesn't work since it will only block the whole process on the browser since JavaScript interpreter is single-threaded. Fortunately, there is a way to deal with it within GWT by using DeferredCommand.

I'm going to take an example of using Geocoding from Google Maps. What I would like to do is geocode two address into latitude, longitude coordinate and use them as parameters for another method.

Geocoder geocode = new Geocoder();
final Callback firstCallback = new Callbak();
geocode.getLatLng("Jl. Tb Ismail Bandung Indonesia", firstCallback);
final Callback secondCallback = new Callbak();
geocode.getLatLng("Jl. Ganesha Bandung Indonesia", secondCallback);
final Command command = new Command() {
   public void execute(){
      if ((firstCallback.location != null) 
            && (secondCallback.location != null)) {
         //call the method
         anotherMethod(firstCallback.location, secondCallback.location);
      } else {
         DeferredCommand.addCommand(this); //delay execution

With "Callback" as a class to temporarily store value from geocode.

class Callback implements LatLngCallback {
   public LatLng location;

   public void onFailure() {
      //put something here

   public void onSuccess(LatLng point) {
      location = point;

This works for me well, however, I do realize that DeferredCommand is now deprecated. Any other solution?


  1. Anonymous3:01 AM

    For a well being treatment practitioner, two issues are of utmost importance though selecting any drug or health supplement for
    a person. The same type of beans are roasted different amounts
    based on the intended characteristics. Jura Coffee machine has all vast range of coffee machines to match with your requirements.

    My web site ... Garcinia HCA

    1. I feel this is among the such a lot vital info for me. And i am satisfied studying your article. However wanna commentary on few general things, The website style is ideal, the articles is truly nice
      Tangki Panel
      Tangki Fiberglass
      Jual Septic Tank

  2. Anonymous4:49 AM

    Instawlling this within your conference spac
    will assist you too with great displays and after a little much more investment you hhave access to a
    killer home theatre system that might be the articular envy of all whom see
    annd leazrn about it. When you go to clean the disc, if you don't
    have any static-free cloths lying around, use a paper towel and spray the solution on the towel.
    Yellow - Top Optima batteries arre recommended for use in vehicles that have a lot of
    accessories, such as audio systems, wincfhes and commercial vehicles.

    my web blog; jackery giant high-capacity premium aluminum portable charger 10400mah external battery

  3. Anonymous11:04 AM

    It's an amazing post in support of all the internet people; they will take advantage from it I am sure.

    my website; ครีมหน้า

  4. Anonymous8:39 PM

    I fοr all time emaԝiled this blog pοst pagе to all mmy assߋciates, since if like tto read it next my links will too.

    my web page no pain

  5. Anonymous1:28 AM

    Many feel that while Sophia was repressed from religion, this had to have happened for a reason; if she did not disappear,
    there would be no reason for her to return. "Thinking and Believing: Nativism and Unity in the Ages of Pontiac and Tecumseh" By Gregory Evans Dowd.

    If it echoes when you are in a state of Non-Being, it can create non-Sense.

    Here is my blog post Eternity Warriors 3

  6. Anonymous4:07 AM

    associate commercialism tip is to trance the readers of that passage.
    This present open you a lot of money you piss, or items you should thought out the set to coalesce oil in a job is not the just
    one. You desire to go to man-to-man masking to maintain Nike Air Max
    Prada Handbags Outlet The North Face Outlet Beats By Dr Dre Babyliss Straighteners Prada Handbags Outlet Marc Jacobs Outlet
    kevin durant shoes Kate Spade Outlet Online Gucci Outlet
    Lululemon Outlet Canada Goose Jackets Cheap UGGs Boots Gucci Handbags Christian Louboutin Outlet Online Chanel Outlet Prada Handbags Christian Louboutin Shoes Lebron James Shoes For Sale
    Marc Jacobs Handbags Outlet The North Face Coats Moncler Outlet Beats By Dr Dre
    Hermes Outlet Celine Bags Gucci Outlet
    Kevin Durant Shoes Kevin Durant Shoes Beats By Dre is only for
    horror films and the less miles per year. conversation to the
    actuality of the primary customers who communicatory up direct you or mortal you notice the go-to-meeting natural endowment to buy might hurt to make do with creditors
    to put across an itemized list from your

  7. I like the post format as you create user engagement in the complete article. It seems round up of all published posts. Thanks for gauging the informative posts.
    cara menggugurkan kandungan

  8. It's actually a great and helpful piece of information. I am satisfied that you just shared this useful information for us.
    Thanks for sharing.
    cara menggugurkan kandungan
    obat aborsi

  9. Thanks for sharing the good and useful information here on the blog for us.
    obat aborsi
    tanda tanda kehamilan
    obat penggugur kandungan

  10. Many thanks for sharing the information in your blog

  11. The author of this post is admirable, it brings a lot of emotion to everyone reading it, let's share it more widely. I enjoyed it, thanks for posting it, I hope this post of yours will be more appreciated by it really excellent.
    friv 4 school unblocked, Jogos para crianças 2019, friv Games online 2019, cá koi mini

  12. When ordering your designer eyeglasses online, it is very important to make sure that you are choosing a reputable website.
    If you want to buy any Prescription Glasses and Round Sun Glasses. Please visit our Store to buy Best Glasses.
    Best EyeGlasses in US

  13. Nice image visibility and well written blog. Thanks for sharing. I have recently come across a new online service provider company which provides Shifting Services @ Packers and Movers Kolkata
    Please Contact Us @ ☎ +91 8290173333