我在我的 vb.net 2010 应用程序上使用 Google Maps API V3。我http://maps.google.com/maps/geo?output=csv&key=MYAPIKEY&q= 46 long street, kempton park
直接在网络浏览器上 进行了测试,但610,0,0,0
出现错误。我的应用程序的重点是从地址获取 gps 坐标,并从给定的 gps 坐标获取地址。我尝试生成一个新的浏览器密钥,但仍然无法正常工作。提前致谢。请参考以下代码:
有人可以告知为什么 Google Maps API 返回此610,0,0,0
错误
Public Function GetLatLon(ByVal addr As String) As LatLon
Dim url As String = "http://maps.google.com/maps/geo?output=csv&key=MYAPIKEY" & addr
Dim request As System.Net.WebRequest = WebRequest.Create(url)
Dim response As HttpWebResponse = request.GetResponse()
If response.StatusCode = HttpStatusCode.OK Then
Dim ms As New System.IO.MemoryStream()
Dim responseStream As System.IO.Stream = response.GetResponseStream()
Dim buffer(2048) As Byte
Dim count As Integer = responseStream.Read(buffer, 0, buffer.Length)
While count > 0
ms.Write(buffer, 0, count)
count = responseStream.Read(buffer, 0, buffer.Length)
End While
responseStream.Close()
ms.Close()
Dim responseBytes() As Byte = ms.ToArray()
Dim encoding As New System.Text.ASCIIEncoding()
Dim coords As String = encoding.GetString(responseBytes)
Dim parts() As String = coords.Split(",")
Return New LatLon(Convert.ToDouble(parts(2)), Convert.ToDouble(parts(3)))
End If
Return Nothing
End Function