issues in Distance Matrix Service

1,320 views
Skip to first unread message

Benjamin Heyman

unread,
May 16, 2011, 11:09:57 AM5/16/11
to google-map...@googlegroups.com
I would like to report a few issues about Distance Matrix Service : when you enter an erratic origin or destination address (like "sdfdsf, sdfsdfsd, France") or when the driving distance could not be calculated (like a France-Cuba distance for instance), The service will never send back the status "NOT_FOUND" or "ZERO_RESULT", but "" (or "OK" for a valid address). So you can't tell your visitor where he's wrong.
Also, in this version 3, if you enter "312, France" as an origin address, the response.Originadresses will be "312 France, 47200 Virazeil, France", which is erratic too.
Although this service is a great enhancement for valid addresses, it carries many issues when addresses are wrong. That would be great to fix those issues.

Enoch Lau

unread,
May 16, 2011, 11:35:59 AM5/16/11
to google-map...@googlegroups.com
Hi, thanks for the feedback.

NOT_FOUND and ZERO_RESULTS are element statuses, i.e. they are the potential status of an individual element of the response not of the entire response. In other words, it is possible for elements of the matrix to have the status NOT_FOUND or ZERO_RESULTS, but for the overall response to have the status of OK. You should therefore check the status of the elements of the matrix to determine whether the addresses entered can't be located (NOT_FOUND) or whether there is no route between a pair of addresses (ZERO_RESULTS).

Can you give me an example of a request where the status is the empty string ""? I can't reproduce it.

If you plug in "312, France" into the Directions Service, it also treats it as "312 France, 47200 Virazeil, France" - do you believe that this should be treated as an invalid address?

Benjamin Heyman

unread,
May 16, 2011, 12:09:37 PM5/16/11
to google-map...@googlegroups.com
Hi, thanks for your quick answer.
You can see my example here. I've tried many ways, I may have used the wrong syntax, for Google doesn't tell much about it.
In this example, I can't obtain any alert on an erratic destination address (see if(arr!=''){...}else{alert...}). Same problem if I ask to alert(element.status) : the answer will be 'OK' for a valid address, '' for a wrong one instead of 'NOT_FOUND'. By the way, an erratic origin address will generate an alert whereas an erratic one will not, I don't understand why but perhaps my code is wrong.
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. That issue didn't appear in version 2. 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).

Kind regards,

Benjamin


2011/5/16 Enoch Lau <enoc...@google.com>:
> --
> 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 google-map...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-maps-js-a...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-maps-js-api-v3?hl=en.
>

Rossko

unread,
May 16, 2011, 3:43:26 PM5/16/11
to Google Maps JavaScript API v3
> 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.

Enoch Lau

unread,
May 16, 2011, 4:23:14 PM5/16/11
to google-map...@googlegroups.com
If I make a request from France to aksdhlaksdhjasd using your script, it throws an exception line 56: var dist = element.distance.value;
This is because you should check the status of the element (which is NOT_FOUND) before you request the distance, which you're currently not doing.

You are currently testing the returned origin and destination addresses against the empty string to determine whether a particular address was understood or not; instead, you should examine the status of the corresponding element - if it is NOT_FOUND, then it means that either of the origin or destination for that element was not understood.

If you are concerned that your customers may be entering in addresses that are then interpreted to be something other than what they intended, would it be possible for you to display the returned origin/destination address and confirm with them that that is in fact what they wanted?

Benjamin Heyman

unread,
May 17, 2011, 4:35:37 AM5/17/11
to google-map...@googlegroups.com
Wonderful !!
Shame on me, I should have been using a javascript debugger. Now the script works and can even tell whether the visitor was wrong about the origin address, the destination address or if the driving distance can not be calculated, you can try it. I'll post it asap for the community. However let's notice that my script couldn't distinguish origin or destination mistakes with multiple addresses.
About your latest remark, I do have to display the returned origin/destination address to ask my customers to confirm them, but I'd rather avoid that as the form is quite heavy so far.
Thank you very much for your help. Best regards.

2011/5/16 Enoch Lau <enoc...@google.com>
--

Benjamin Heyman

unread,
May 17, 2011, 5:30:15 AM5/17/11
to google-map...@googlegroups.com
Sorry Rossko, I didn't receive your comment on my email box.
Actually I didn't know about the map that must be related to the use of the service. I do now, and I understand that, thank you for your remark.
To everybody, the attached file contains the working script. It may not be totally rigorous so don't hesitate to correct it if so.
distance2.html
Reply all
Reply to author
Forward
0 new messages