Last week, I described how I'd used a Google API to allow a Google Spreadsheet to drive items appearing on a Google Map. I was proud of the work. Rob was less impressed, instead focusing on the fact that the latitude and longitude had to be looked up and input manually based on the postcode or town being mapped. He's never impressed, that boy.
In a comment on the original post, Mercedes Car Finder (a person, it seems) suggested a Google formula, as follows:
=ImportData("http://maps.google.co.uk/maps/geo?output=csv&q="&A1)
where A1 contains the item to be looked up—the postcode or placename. Let's assume the formula is entered into B1.
The CSV file resulting from the URL contains four fields. For "York", the first two numbers are 200 and 4. (I have no idea what these are. Anyone?) The last two (53.957702 and -1.082286) are the latitude and longitude respectively.
So the ImportData function brings back all four values, but only stores the first of these (200) in the cell containing the formula, in this case B1. The subsequent three values are accessed through the formulae
- =CONTINUE(B2,1,2)
- =CONTINUE(B2,1,3)
- =CONTINUE(B2,1,4)
Given that the CSV file returned has a single row of data, these formulae bring back the mysterious 4, 53.957702 and -1.082286 respectively.
Unfortunately, Google doesn't allow you to create latitude in one step through the following syntax:
- =CONTINUE(ImportData("http://maps.google.co.uk/maps/geo?output=csv&q="&A2),1,3)
But nonetheless, if I have a column of postcodes or placenames, all I need is three columns of formulae (the ImportData formula containing the 200, the CONTINUE (3) formula containing the latitude and the CONTINUE (4) formula containing the longitude) to feed the map.
Fabulous. Thanks, Mercedes-selling-person.
