我相信Google API可以讓您獲得給定地址的座標。然而,我發現的大多數(或者應該說全部)例子都不適用於vb。通常這是一些JavaScript例子,只是讓我感到困惑。從地址獲取GPS座標的代碼(VB6/VBA/VBScript)
這是我使用地理編碼服務的一些代碼。這很好。這只是我想直接查詢Google地圖。
Public Function fgGetLatAndLongUsingAddress(sAddress As String) As String
'This function works best with a complete address including the zip code
Dim sResponseText As String, sReturn As String
sReturn = "none"
Dim objHttp As Object, sQuery As String
sQuery = "http://rpc.geocoder.us/service/csv?address=" & Replace(sAddress, " ", "+")
Set objHttp = CreateObject("Msxml2.ServerXMLHTTP")
objHttp.Open "GET", sQuery, False
objHttp.send
sResponseText = objHttp.ResponseText
gsLastLatLongResponseText = sResponseText
Set objHttp = Nothing
If Len(sResponseText) > 0 Then
If InStr(sResponseText, "Bad Request") > 0 Then
'Do Nothing
ElseIf InStr(sResponseText, "couldn't find this address") > 0 Then
'Do Nothing
Else
If InStr(sResponseText, vbCrLf) > 0 Then
'We got more than one result
End If
If InStr(sResponseText, ",") > 0 Then
Dim aryInfo() As String
aryInfo = Split(sResponseText, ",")
sReturn = aryInfo(0) & "," & aryInfo(1)
End If
End If
End If
fgGetLatAndLongUsingAddress = sReturn
End Function
+1表示技術的正確性,-1表示可能違反Google的地理編碼服務[條款和條件](https://developers.google.com/maps/documentation/geocoding/)。 Quote:*地理編碼API只能與Google地圖一起使用;不允許在[Google]地圖上顯示地理編碼結果。* – MarkJ 2013-08-12 14:49:25