General Question

se_ven's avatar

Scrape GPS Coordinates in to Excel?

Asked by se_ven (789points) August 5th, 2009

Does anyone know of a way to get GPS Coordinates from a site like Yahoo or Google and into Excel?

I’m wanting to create a spreadsheet where a user can enter an address and then execute a Macro that will send the Address to Yahoo or Google and then get the GPS Coordinates back for that address. These Coordinates would then be compared against a Database of other records.

Here’s what I now already:
– In Yahoo Maps: When logged in with a Yahoo ID, the Latitude and Longitude shows up in the address bar after searching for the address.
– In Google Maps: After a search is done the Latitude and Longitude are in the source code and can be scraped out by using a text identifier like “lat:” or “lng:”

I’ve done this in FileMaker, but think for this user Excel would be the best option. (I would be willing to try this with PHP or Python too if that is a better option)

Observing members: 0 Composing members: 0

8 Answers

se_ven's avatar

Thanks @gt4329b. I’ll check it out, but there might be more of a learning curve on my part than I want for this type of solution.

What all is involved? Java Script, HTML, etc?

reactor5's avatar

try looking for a RESTful interface. geocoder.us has one. Basically you tell excel to get data from somewhere like:

“http://username:password@geocoder.us/member/service/csv/geocode?address=1600+Pennsylvania+Ave,+Washington+DC”

which returns this:

“38.898748,-77.037684,1600 Pennsylvania Ave NW,Washington,DC,20502”

So now the first two values of that CSV list are your lat and long (or long and lat, I’m not sure on the order offhand).

I would definitely do it in javascript, because that would be easiest for me, but I’m fairly certain that excel can get a url and have the data be what’s returned. From there, you just need to separate the CSV.

BTW: more info here and search for “REST-CSV”

se_ven's avatar

Ok! I seemed to get it to work using @reactor5‘s advice and this article

If anyone is trying to do something similar I’ve included my code below (Excel VBA). Basically I have a worksheet with “Address, City, State, Zip, Latitude, Longitude” in cells A1 to F1 and Below “Address, City, State, Zip” is where the user would type in the address. The Latitude and Longitude are then put in the cells below their respective headings. I probably need to add some error handling if the address doesn’t come up right on the website, but this does the trick for a good address.

The Macro Looks Like this:

Sub GetLatLong()

’ GetLatLong

Dim iAddr As String
Dim iCity As String
Dim iST As String
Dim iZip As String
Dim WebAddr As String
Dim WebRslt As String
Dim Pos1 As Long
Dim Pos2 As Long

iAddr = WorksheetFunction.Substitute(Trim(Range(“A2”)), ” ”, ”+”)
iCity = WorksheetFunction.Substitute(Trim(Range(“B2”)), ” ”, ”+”)
iST = Trim(Range(“C2”))
iZip = Trim(Range(“D2”))
WebAddr = “http://rpc.geocoder.us/service/csv?address=” & iAddr & ”,” & iCity & ”+” & iST & ”+” & iZip

With ActiveSheet.QueryTables.Add(Connection:=“URL;” & WebAddr, Destination:=Range(”$H$1”))
.Name = “Link”
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = False
.AdjustColumnWidth = False
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With

WebRslt = Range(“H1”)
Pos1 = WorksheetFunction.Find(”,”, WebRslt)
‘MsgBox Pos1
Pos2 = WorksheetFunction.Find(”,”, WebRslt, Pos1 + 1)
‘MsgBox Pos2

Range(“E2”) = Left(WebRslt, Pos1 – 1)
Range(“F2”) = Mid(WebRslt, Pos1 + 1, Pos2 – Pos1 – 1)

Range(“H1”, “J1”).Columns.Delete
Range(“H1”).Select
Selection.QueryTable.Delete
Selection.ClearContents
End Sub

phoenyx's avatar

What you want sounds like a simple web app. Why do you need to involve Excel?

se_ven's avatar

Mostly because I’m not that familiar with creating web apps, and this small of a solution isn’t worth learning how to create a web app at the time. I know excel pretty well, and it can do what I need it to…so why not? :)

phoenyx's avatar

fair enough

SmirkingMan's avatar

I’ve developed an addin for Excel which does forward/reverse geocoding and GCD with GoogleMaps. Freeware: http://www.calvert.ch/geodesix/

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther