vb код для геокодирования адреса в latlong
Привет ,
Я пытаюсь использовать код brow, но всегда получаю ошибку "удаленный сервер вернул ошибку: (403) Forbidden. "в строке" Dim response As HttpWebResponse = request.GetResponse ()".
Я заменил [ваш ключ идет сюда] своим ключом (-> необходимы ли [ ]?).
кто-нибудь может помочь?
Private Sub Geocode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Geocode.Click txtLatLon.Text = GetLatLon(txtAddress.Text) End Sub
Public Function GetLatLon(ByVal addr As String) As String Dim url As String = "http://maps.google.com/maps/geo?output=csv&key=[YOUR KEY GOES HERE]&q=" & 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 Convert.ToDouble(parts(2)) & Convert.ToDouble(parts(3)) End If Return Nothing End Function