No announcement yet.

Convert GPS Coordinates to an Address?

  • Filter
  • Time
  • Show
Clear All
new posts

    Convert GPS Coordinates to an Address?

    I have the GPS coordinates is there a script around that can convert the LAT/LON to an actual address or city/town and write to HS log?


    What you want is a reverse Geocoding service, Google offer it as well as Bing. Here is the Bing documents as an example -

    You would need to call the URL (the .net XML library will get a URL of data for you) and then decode the XML response but that is not that hard.


      Here's a script that will take a lat/long and convert to an address and save the address to a virtual device. Call the script by passing the following parameters to it: Lat,long|Device. Lat,Long should be in decimal format and Device is the reference ID of the device to save the address to. It uses Bing for which you need to get your own API Key.

      Imports System.IO
      Sub Main(ByVal Parms As Object)
          Dim APIKey As String = "YourOwnBingAPIKey"
          Dim Debug as Boolean = True
          Dim logName = "Bing Geocode"                    'set log type for HS log
          Dim hs_path As String = hs.GetAppPath
          Dim DebugFile As String = hs_path & "\Logs\DebugFileBing.xml"
          Dim ParmArray() as String
          ParmArray = Parms.tostring.split("|")            'split parameter into an array
          Dim LatLong = ParmArray(0)                        'Starting Location: lat,long
          Dim targetDev as Double = CDbl(ParmArray(1))    'reference ID of the device for which to update value
              Dim XMLData As New XmlDocument
              Dim URLString As String = "" & LatLong & "?o=xml&key=" & APIKey
              Dim sNS As String = XMLData.DocumentElement.Attributes("xmlns").Value
              Dim oNsMgr = New XmlNamespaceManager(XMLData.NameTable)
              oNsMgr.AddNamespace("def", sNS)
              If Debug Then
                  If File.Exists(DebugFile) Then File.Delete(DebugFile)
              End If
              Dim Address As String = XMLData.SelectSingleNode("//def:Name", oNsMgr).InnerText
              hs.SetDeviceString(targetDev, Address, False)
              If Debug Then hs.writelog(logName, Address)
              XMLData = Nothing
              URLString = Nothing
              sNS = Nothing
              oNsMgr = Nothing
              Address = Nothing
          Catch ex As Exception : hs.writelog(logName, "Error:  " & ex.Message.ToString)
          End Try
          ParmArray = Nothing
      End Sub
      Click image for larger version

Name:	Capture.PNG
Views:	144
Size:	19.0 KB
ID:	1266827
      HS 2134 Devices 1252 Events
      Z-Wave 133 Nodes on one Z-Net