Hi there,
I also believe is a synchnonization problem.
You cannot be sure that the mapStart and mapEnd variables have already
been set when you call calcularRota().
I would first set them to null at the beginning of the click function,
then make the two asynchronous calls and then wait for them to be set,
before calling the calcularRota function.
while(mapStart==null || mapEnd==null) {
 // do nothing
}
Or keep track of the response status in two separate variables
(mapStartCalcDone and mapEndCalcDone) which manage also the case in
which the response is returned but the result itself is null.
The best would be to sleep inside the while, but I remember there's no
sleep in javascript.

Hope it helps,
Davide

On Jun 28, 4:51 pm, "Ph.E" <[email protected]> wrote:
> Camarades,
>
> I'm having trouble getting the position of an address. However, this
> problem occurs only the first time that I run, ie it is necessary that
> every time I make the query, I click twice, for only the second values
> are obtained.
>
> I believe the problem is due to be asynchronous method. But I am not
> able to solve the problem. Some of his friends could help me.
>
> Code:
>
> $('#btnTracar').click(function(){
>         if (geocoder){
>                 geocoder.geocode({ 'address':
> document.getElementById('txtStart').value }, function(results, status)
> {
>                         if (status == google.maps.GeocoderStatus.OK) {
>                                 mapStart = results[0].geometry.location;
>                         } else { alert("Não foi possível carregar a 
> localização.
> \nDescrição do Erro: " + status); }
>                 });
>
>                 geocoder.geocode({ 'address':
> document.getElementById('txtEnd').value }, function(results, status){
>                         if (status == google.maps.GeocoderStatus.OK) {
>                                 mapEnd = results[0].geometry.location;
>                         } else { alert("Não foi possível carregar a 
> localização.
> \nDescrição do Erro: " + status); }
>                 });
>
>                 calcularRota();
>         }
>
> });

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply via email to