3

I've used this query to calculate distance between two locations, now it won't work anymore, and returns the error xPath query didn't get any result (translated from Italian, I don't know if is the same in English).

This is the query:

=INT(SUBSTITUTE(INDEX(importXML("http://maps.google.com/maps?saddr="&SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE( C5 ;CHAR(13);" ");CHAR(10);" ")); " "; "+")&"&daddr="&SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE( E16 ;CHAR(13);" ");CHAR(10);" ")); " "; "+")&"&ie=UTF8&hl=it&output=mobile&f=d&btnG=Get+Directions" ; "//span[1]" ) ; 1);" km";""))

what's the problem? Should I update this method because it's deprecated?

1

1 Answer 1

3

Getting data by parsing the HTML source of a page is a fragile method: when the pages gets redesign, the import is most likely going to break down because the data you want are not where you expect. It's no coincidence that most of examples on Google's own IMPORTXML documentation page are broken by now.

I recommend using Google Distance Matrix API instead (it is a subset of Google Maps API). It also accepts HTTP requests and can return data as XML; but this XML will have predictable, documented structure for the lifetime of the API version.

Examples of parsing Google's XML response with XPath are found here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.