Lasse9,
I've just found the symbolic figures.
If you put any city in A2, it points to the City hall in most cases.
And also fixed the error when exceeds the connection limit.
Try
Public Function GetLatLng(start As String, LtLn As String)
Dim firstVal As String, URL As String, txt As String
firstVal = "https://maps.googleapis.com/maps/api/geocode/json?address="
URL = firstVal & Replace(start, " ", "+")
With CreateObject("MSXML2.ServerXMLHTTP")
.Open "GET", URL, False
.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
.send ("")
txt = .responseText
End With
If InStr(txt, "error_message") Then GetLatLng = GetLatLng(start, LtLn)
LtLn = LCase$(LtLn)
With CreateObject("VBScript.RegExp")
.Pattern = "formatted_address"" *: *""(.+?)"",([\r\n]+.+)+?""location_type"" :"
If .test(txt) Then
txt = .Execute(txt)(0)
Else
Exit Function
End If
If LtLn = "address" Then
GetLatLng = ""
.Pattern = "formatted_address"" *: *""(.+?)"""
If .test(txt) Then GetLatLng = .Execute(txt)(0).submatches(0)
Else
.Pattern = "location"" *:.+([\r\n]+.+)+?\}"
txt = .Execute(txt)(0)
.Pattern = """" & LtLn & """ *: *([+-]?\d+(\.\d+)?)"
If .test(txt) Then GetLatLng = Replace(Val(.Execute(txt)(0).submatches(0)), _
".", Application.International(xlDecimalSeparator))
End If
End With
End Function
Bookmarks