« MBS Plugin Advent cal… | Home | Use Perform Script on… »

MBS Plugin Advent calendar: 11 - WindowsLocation

Door 11 - WindowsLocation

Fact of the day
Did you know that one of the reasons why the Greenwich meridian became established was because the area on the other side, i.e. the International Date Line, was sparsely settled? This had the advantage that you rarely had to add a whole day when you were traveling. This avoided confusion.

In Door 8 we have already seen how we can determine a location from a Mac or an iOS device. With the WindowsLocation component, we also have a way to determine the location for Windows.

First we have to initialize the location functions for Windows with the function WindowsLocation.Initialize. Once this has worked, we ask Windows for permission to query the location. To do this, we use the WindowsLocation.RequestPermissions function. Now we can get the following statuses with WindowsLocation.Status.

  • Not supported
  • Error
  • Access Denied
  • Initializing
  • Running
If we have Running, we can query the location with WindowsLocation.Location. We then receive a JSON with our data that can look like this, for example:
{
    "Latitude":    50.4833,
    "Longitude":    7.4655,
    "Altitude":    0,
    "ErrorRadius":    6713,
    "AltitudeError":    0,
    "SensorID":    "{00000000-0000-0000-0000-000000000000}",
    "Timestamp":    "06.12.2023 12:38:40,532"
}

We can then read this information from the JSON using JSON functions. For example, here we see the script step with which we read the latitude:

...
Set Variable [ $JSON ; Value: MBS( "WindowsLocation.Location" ) ] 
# 
Set Variable [ $lat ; Value: JSONGetElement ( $JSON ; "Latitude") ] 
Set Field [ DoorEleven::Latitude ; $lat ] 
...

I hope you enjoy identifying your location

Monkeybread Software Logo with Monkey with Santa hat
10 👈 11 of 24 👉 12
11 12 23 - 08:06