Announcement

Collapse
No announcement yet.

Convert GPS Coordinates to an Address?

Collapse
X
 
  • 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?

    Thanks

  • #2
    What you want is a reverse Geocoding service, Google offer it as well as Bing. Here is the Bing documents as an example - https://msdn.microsoft.com/en-us/library/ff701710.aspx

    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.
    My Plugins:

    Pushover 3P | DoorBird 3P | Current Cost 3P | Velleman K8055 3P | LAMetric 3P | Garadget 3P | Hive 3P |
    Yeelight 3P | Nanoleaf 3P

    Comment


    • #3
      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.

      Code:
      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
      
      
          Try
              Dim XMLData As New XmlDocument
      
              Dim URLString As String = "http://dev.virtualearth.net/REST/v1/Locations/" & LatLong & "?o=xml&key=" & APIKey
      
              XMLData.Load(URLString)
      
              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)
                  XMLData.Save(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:	23
Size:	19.0 KB
ID:	1266827
      HS 3.0.0.548: 1970 Devices 1149 Events
      Z-Wave 3.0.1.262: 123 Nodes on one Z-Net

      Comment

      Working...
      X