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 , 43 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() {
   @Override
   public void execute(){
      if ((firstCallback.location != null) 
            && (secondCallback.location != null)) {
         //call the method
         anotherMethod(firstCallback.location, secondCallback.location);
      } else {
         DeferredCommand.addCommand(this); //delay execution
      }
   }
}
command.execute();

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

class Callback implements LatLngCallback {
   public LatLng location;

   @Override
   public void onFailure() {
      //put something here
   }

   @Override
   public void onSuccess(LatLng point) {
      location = point;
   }
}

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

43 comments:

  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

    ReplyDelete
  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

    ReplyDelete
  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; ครีมหน้า

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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

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

    ReplyDelete