Re: Problem with Asynchronous callback

2010-03-29 Thread Eric Ayers
I think you can trace what's going on by putting in a few calls to
Window.alert().  The calls to getLatLng() have to go across to
Google's servers and may take many milliseconds to return.  You need
some kind of mechanism to make sure all of the LatLngCallbacks fire
before looking at listaCoordinateCittaUtente

On Mon, Mar 29, 2010 at 11:39 AM, Andrea andrea.mor...@gmail.com wrote:
 I have the method getAddress() that take in input an array of cities.
 For each city I use the Asyncronous method getLatLng() that return me
 the coordinates and I save them in an ArrayList called
 listaCoordinateCittaUtente.
 But when I use the ArrayList after the call of the method getAddress()
 it is empty.
 I tried to resolve this problem with the Timer class but it isn't the
 better solution.
 How can I resolve this problem???

 public void getAddress(String address[]){
      final int nCicli=address.length;

       for (int i = 0; i  nCicli; i++) {
         final String nomeCitta=address[i];
                 geocoder.getLatLng(nomeCitta, new LatLngCallback(){
         public void onFailure(){
                 Window.alert(nomeCitta +  non esiste);
         }
         public void onSuccess(LatLng point){
                 listaCoordinateCittaUtente.add(point);
                 map.addOverlay(new Marker(point));
                 map.setCenter(point);
         }
         });
        }
  }

 --
 You received this message because you are subscribed to the Google Groups 
 Google Web Toolkit group.
 To post to this group, send email to google-web-tool...@googlegroups.com.
 To unsubscribe from this group, send email to 
 google-web-toolkit+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/google-web-toolkit?hl=en.





-- 
Eric Z. Ayers
Google Web Toolkit, Atlanta, GA USA
Sign up now for Google I/O 2010: May 19-20, http://code.google.com/io

-- 
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.



Re: Problem with Asynchronous callback

2010-03-29 Thread kozura
Hi Andrea,
I assume you mean the listaCoordinateCittaUtente list doesn't have any
data after this call?  This is the point of an asynchronous call, you
can't predict how long the call will take to come back from the
server, so you actually need to design your app to use the data only
once it is completed.  It looks like you sortof do that with
map.addOverlay, where you're doing something to your map is once the
call comes back; you need to consider the list in the same way.  In
this case, it won't have the complete result until onSuccess has been
called nCicli times.

Also, if there really are many addresses, you would be much better off
making your RPC call take the entire list at once.  For one, there are
only two connections allowed at a time, so making many calls will
quickly cause a bottleneck - one call will be much more efficient than
many.  For two, I'm assuming you actually want to associate these
returned points with their addresses.  There is no guarantee of the
order that onSuccess will be called with the return values, so even
once it is completely filled, lista... list won't be in the same order
as the address array.  Finally, with one call you'll actually know for
sure when the operation is done - the single call of onSuccess.

jk

On Mar 29, 9:39 am, Andrea andrea.mor...@gmail.com wrote:
 I have the method getAddress() that take in input an array of cities.
 For each city I use the Asyncronous method getLatLng() that return me
 the coordinates and I save them in an ArrayList called
 listaCoordinateCittaUtente.
 But when I use the ArrayList after the call of the method getAddress()
 it is empty.
 I tried to resolve this problem with the Timer class but it isn't the
 better solution.
 How can I resolve this problem???

 public void getAddress(String address[]){
       final int nCicli=address.length;

        for (int i = 0; i  nCicli; i++) {
          final String nomeCitta=address[i];
                  geocoder.getLatLng(nomeCitta, new LatLngCallback(){
          public void onFailure(){
                  Window.alert(nomeCitta +  non esiste);
          }
          public void onSuccess(LatLng point){
                  listaCoordinateCittaUtente.add(point);
                  map.addOverlay(new Marker(point));
                  map.setCenter(point);
          }
          });
         }
  }

-- 
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.



Re: Problem with Asynchronous callback

2010-03-29 Thread Andrea
Thanks for your answer.

It's only few days that I use this technology so please tell me how I
can make my RPC call takes the entire list at once.
I can't understand the first solution, can you give me an example of
it??

Andrea

On 29 Mar, 17:54, kozura koz...@gmail.com wrote:
 Hi Andrea,
 I assume you mean the listaCoordinateCittaUtente list doesn't have any
 data after this call?  This is the point of an asynchronous call, you
 can't predict how long the call will take to come back from the
 server, so you actually need to design your app to use the data only
 once it is completed.  It looks like you sortof do that with
 map.addOverlay, where you're doing something to your map is once the
 call comes back; you need to consider the list in the same way.  In
 this case, it won't have the complete result until onSuccess has been
 called nCicli times.

 Also, if there really are many addresses, you would be much better off
 making your RPC call take the entire list at once.  For one, there are
 only two connections allowed at a time, so making many calls will
 quickly cause a bottleneck - one call will be much more efficient than
 many.  For two, I'm assuming you actually want to associate these
 returned points with their addresses.  There is no guarantee of the
 order that onSuccess will be called with the return values, so even
 once it is completely filled, lista... list won't be in the same order
 as the address array.  Finally, with one call you'll actually know for
 sure when the operation is done - the single call of onSuccess.

 jk

 On Mar 29, 9:39 am, Andrea andrea.mor...@gmail.com wrote:



  I have the method getAddress() that take in input an array of cities.
  For each city I use the Asyncronous method getLatLng() that return me
  the coordinates and I save them in an ArrayList called
  listaCoordinateCittaUtente.
  But when I use the ArrayList after the call of the method getAddress()
  it is empty.
  I tried to resolve this problem with the Timer class but it isn't the
  better solution.
  How can I resolve this problem???

  public void getAddress(String address[]){
        final int nCicli=address.length;

         for (int i = 0; i  nCicli; i++) {
           final String nomeCitta=address[i];
                   geocoder.getLatLng(nomeCitta, new LatLngCallback(){
           public void onFailure(){
                   Window.alert(nomeCitta +  non esiste);
           }
           public void onSuccess(LatLng point){
                   listaCoordinateCittaUtente.add(point);
                   map.addOverlay(new Marker(point));
                   map.setCenter(point);
           }
           });
          }
   }- Nascondi testo citato

 - Mostra testo citato -

-- 
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.



Re: Problem with Asynchronous callback

2010-03-29 Thread kozura
Sync version:
ListLatLng getLatLngs(ListString addresses);

Async version:
void getLatLngs(ListString addresses, AsyncCallbackListLatLng
cb);

onSuccess(ListLatLng result)
{
listaCoordinateCittaUtente = result;
doStuffWithResults...;
}

-- 
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.



Re: Problem with Asynchronous callback

2010-03-29 Thread Sripathi Krishnan
Andrea,

You must read the great beer analogy out here -
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/faca1575f306ba0f?pli=1

--Sri


On 29 March 2010 22:47, kozura koz...@gmail.com wrote:

 Sync version:
 ListLatLng getLatLngs(ListString addresses);

 Async version:
 void getLatLngs(ListString addresses, AsyncCallbackListLatLng
 cb);

 onSuccess(ListLatLng result)
 {
listaCoordinateCittaUtente = result;
doStuffWithResults...;
 }

 --
 You received this message because you are subscribed to the Google Groups
 Google Web Toolkit group.
 To post to this group, send email to google-web-tool...@googlegroups.com.
 To unsubscribe from this group, send email to
 google-web-toolkit+unsubscr...@googlegroups.comgoogle-web-toolkit%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/google-web-toolkit?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.