> In this example, I can't obtain any alert on an erratic destination address
> (see if(arr!=''){...}else{alert...})
If I give it a task it can't do, like London to New York, your script
hits a javascript error before getting to your your error checking
code. Your code attempts to get the distance before checking status
to see if distance is available. Results are as already explained,
"status": "OK",
...
"rows": [ {
"elements": [ {
"status": "ZERO_RESULTS"
> Concerning the last issue, I do think it should be treated as an invalid
> address because if the request is about kilometric fees on an online payment
> site for instance, if the customer enters an invalid address and doesn't
> verify it, he could find himself paying more.
Note that use of the service like that without a map would be a
breach of the free terms of use, it would need to be licensed.
http://code.google.com/apis/maps/documentation/javascript/services.html#distance_matrix
"Use of the Distance Matrix API must relate to the display of
information on a Google Map..."
> Also, why should "312, France" be treated as "312 France,
> 47200 Virazeil, France", and not "312, avenue des Champs-Elysées, Paris" for
> example ? (by the way, 312 France isn't a valid street address).
It's a Distance service, NOT an address validation checker. It will
do its best to make some kind of match out of whatever garbage you
give it.
If address validation is important, you should use a more appropriate
service. Use the Geocoder perhaps, and check the results for
accuracy ; show the user the result on a map and ask if that is what
they meant ; etc. When you are confident the input is not garbage,
then call the distance service.