none
Obter latitude e longitude de um endereço no Google Maps com um Windows Form RRS feed

Todas as Respostas

  • Cole um imagem do Seu Grid?

    E especifique nele como você quer?

    Passe também sua conversão que agora ta no VB.NET?


    Fulvio Cezar Canducci Dias

    domingo, 22 de dezembro de 2013 01:00
  • Olá Fúlvio,

    Segue as informações que solicitou e a imagem do grid. Basicamente eu preciso achar a latitude e longitude de cada registro do grid para calcular a distância de cada um deles em relação a um determinado ponto pré-definido o qual já possuo as coordenadas.

    Public Class LatLng
    	Public Property Latitude() As Double
    		Get
    			Return m_Latitude
    		End Get
    		Set
    			m_Latitude = Value
    		End Set
    	End Property
    	Private m_Latitude As Double
    	Public Property Longitude() As Double
    		Get
    			Return m_Longitude
    		End Get
    		Set
    			m_Longitude = Value
    		End Set
    	End Property
    	Private m_Longitude As Double
    
    	Public Sub New()
    	End Sub
    
    	Public Sub New(lat As Double, lng As Double)
    		Me.Latitude = lat
    		Me.Longitude = lng
    	End Sub
    End Class

    Imports System.IO
    Imports System.Net
    Imports System.Web
    Imports Storm.Common.Utils.Extensions
    
    Public Class GoogleMaps
    	Private API_KEY As String = String.Empty
    
    	Public Sub New(api_key As String)
    		Me.API_KEY = api_key
    	End Sub
    
    	Public Sub SetApiKey(key As String)
    		If key.IsNullOrEmpty() Then
    			Throw New ArgumentException("API Key is invalid")
    		End If
    
    		Me.API_KEY = key
    	End Sub
    
    	''' <summary>
    	''' Perform a geocode lookup of an address
    	''' </summary>
    	''' <param name="addr">The address in CSV form line1, line2, postcode</param>
    	''' <param name="output">CSV or XML</param>
    	''' <returns>LatLng object</returns>
    	Public Function GetLatLng(addr As String) As LatLng
    		Dim url = "http://maps.google.co.uk/maps/geo?output=csv&key=" & Me.API_KEY & "&q=" & HttpContext.Current.Server.UrlEncode(addr)
    
    		Dim request = WebRequest.Create(url)
    		Dim response = DirectCast(request.GetResponse(), HttpWebResponse)
    
    		If response.StatusCode = HttpStatusCode.OK Then
    
    			Dim ms = New MemoryStream()
    			Dim responseStream = response.GetResponseStream()
    
    			Dim buffer = New [Byte](2047) {}
    			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 = ms.ToArray()
    			Dim encoding = New System.Text.ASCIIEncoding()
    
    			Dim coords = encoding.GetString(responseBytes)
    			Dim parts = coords.Split(",")
    
    			Return New LatLng(Convert.ToDouble(parts(2)), Convert.ToDouble(parts(3)))
    		End If
    
    		Return Nothing
    	End Function
    End Class


    Abilio Aguiar

    domingo, 22 de dezembro de 2013 15:24
  • OK, Entendi !!!

    Mas quais campos você utiliza e qual a duvida ?


    Fulvio Cezar Canducci Dias

    domingo, 22 de dezembro de 2013 23:01