Jak uzyskać szerokość i długość geograficzną dla adresów?

Obecnie pracuję z listą danych i jedną z moich kolumn danych jest adres oferty. Planuję wykreślić każdy z moich adresów na mapie Google, ale chciałbym uniknąć konieczności ręcznego wklejania adresu do Google, aby uzyskać parametry. Potrzebuję długości i szerokości geograficznej. Mój arkusz Excel (lub mam go w arkuszu kalkulacyjnym Google Docs) zawiera około 500 adresów.

Więc miałem nadzieję, że jest jakiś sposób, aby zrobić to automatycznie?

Author: pnuts, 2014-03-03

4 answers

Dzięki Uprzejmości tego wspaniałego posta http://policeanalyst.com/using-the-google-geocoding-api-in-excel/

Function GoogleGeocode(address As String) As String
Dim strAddress As String
Dim strQuery As String
Dim strLatitude As String
Dim strLongitude As String

strAddress = URLEncode(address)

'Assemble the query string
strQuery = "http://maps.googleapis.com/maps/api/geocode/xml?"
strQuery = strQuery & "address=" & strAddress 
strQuery = strQuery & "&sensor=false"

'define XML and HTTP components
Dim googleResult As New MSXML2.DOMDocument
Dim googleService As New MSXML2.XMLHTTP
Dim oNodes As MSXML2.IXMLDOMNodeList
Dim oNode As MSXML2.IXMLDOMNode

'create HTTP request to query URL - make sure to have
'that last "False" there for synchronous operation

googleService.Open "GET", strQuery, False
googleService.send
googleResult.LoadXML (googleService.responseText)

Set oNodes = googleResult.getElementsByTagName("geometry")

If oNodes.Length = 1 Then
For Each oNode In oNodes
  strLatitude = oNode.ChildNodes(0).ChildNodes(0).Text
  strLongitude = oNode.ChildNodes(0).ChildNodes(1).Text
  GoogleGeocode = strLatitude & "," & strLongitude
 Next oNode
 Else
 GoogleGeocode = "Not Found (try again, you may have done too many too fast)"
 End If
 End Function


Public Function URLEncode(StringVal As String, Optional SpaceAsPlus As Boolean = False) As String
Dim StringLen As Long: StringLen = Len(StringVal)

If StringLen>0 Then
ReDim result(StringLen) As String
Dim i As Long, CharCode As Integer
Dim Char As String, Space As String

If SpaceAsPlus Then Space = "+" Else Space = "%20"

For i = 1 To StringLen
  Char = Mid$(StringVal, i, 1)  
  CharCode = Asc(Char)

  Select Case CharCode
  Case 97 To 122, 65 To 90, 48 To 57, 45, 46, 95, 126
    result(i) = Char
  Case 32
    result(i) = Space
  Case 0 To 15
    result(i) = "%0" & Hex(CharCode)
  Case Else
    result(i) = "%" & Hex(CharCode)
  End Select
Next i
URLEncode = Join(result, "")
End If
End Function
 10
Author: Chris,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-09-23 21:59:34

Możesz dodać trochę googl apps script do arkusza kalkulacyjnego google, więc zrobi to za Ciebie. Tutaj demo (Dodaj adres i będzie geokodować go dla Ciebie).
I poniżej kodu do wykonania geokodowania:

function getLatLong(adress) {
  try{
    if(adress=="")return("");
    var geo = Maps.newGeocoder().geocode(adress);
    if(geo.status=="OK"){
      var lng = geo.results[0].geometry.viewport.southwest.lng;
      var lat = geo.results[0].geometry.viewport.southwest.lat;
      return([lat,lng]);
    }
    else{
      return("error");
    }
  }
  catch(err){
    return(err);
  }
}
 6
Author: Harold,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-03-03 11:12:53

SmartyStreets oferuje geokodowanie adresów amerykańskich i międzynarodowych. Jest bardzo łatwy w użyciu-wklej swoją listę w ich narzędziu internetowym i zwraca szerokość i długość geograficzną w ciągu kilku sekund. Istnieją inne usługi, które mogą zwracać dane lat/long w podobny sposób; najbardziej znam SmartyStreets, ponieważ tam pracuję.

Należy również pamiętać, że wklejanie adresów do Google Maps niekoniecznie daje dokładne informacje, ponieważ Google nie weryfikuje adres pierwszy; SmartyStreets robi, co zapewnia, że otrzymujesz dane o rzeczywistych lokalizacjach zamiast najlepiej zgadywać Google.

Inne rozwiązania, które warto sprawdzić: AddressDoctor, Loqate, lub innych" międzynarodowych dostawców geokodowania adresów " (szybkie wyszukiwanie w Google pojawi się kilka świetnych opcji).

 1
Author: Michelle,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-09-23 19:18:34

Zamiast wstrzykiwania kodu zalecałbym przeniesienie danych do arkuszy kalkulacyjnych google i włączenie geocode za pomocą niesamowitego dodatku table. Od tego momentu po prostu umieść adresy w jednej kolumnie i wybierz kolumnę adresu do geocode

 0
Author: Lawrence Chang,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-03 18:53:27