Sample code

Sample code

The following code shows an example of how to infer the floor information from the altitude of a location update, and convert the (lat, lon) coordinates to pixel (x, y) to ease display on an image map.

1import matplotlib.pyplot as plt
2import requests
3from PIL import Image
4 
5# NAO Cloud Info
6NAOCLOUD_URL = "www.nao-cloud.com"
7AUTH_TOKEN = "YOURTOKEN"
8SITE_ID = 11805
9 
10# Location update data retrieved via /locs MQTT topic or via the nao_trackables REST API
11LOCATION = {'lon'-80.16644294783441'lat'25.777023335006763'alt'75.0}
12 
13# NAO Cloud REST API calls to get floors metadata (altitude and georeferencing info)
14buildings_url = 'https://%s/api/v2/sites/%s/buildings' % (NAOCLOUD_URL, SITE_ID)
15building_id = requests.get(buildings_url, headers={'Authorization': AUTH_TOKEN}).json()['data'][0]['id']
16floors_url = 'https://%s/api/v2/sites/%s/buildings/%s/floors' % (NAOCLOUD_URL, SITE_ID, building_id)
17floors_data = requests.get(floors_url, headers={'Authorization': AUTH_TOKEN}).json()['data']
18 
19# Get the floor data for the location update (floor number and georeferencing metadata)
20location_update_floor_data = [a for in floors_data if a['attributes']['relative_altitude'== LOCATION['alt']][0]
21location_update_floor= location_update_floor_data['attributes']['level_number']
22map_image = 'maps/floor ' + str(location_update_floor) + '.png'
23location_update_floor_georeferencing_data = location_update_floor_data['attributes']['georeference_info']
24 
25 
26# Function allowing the conversion from WGS84 (lat, lon) coordinates to pixel (X, Y)
28def wgs84_to_pixels(longitude, latitude):
29    LonX = location_update_floor_georeferencing_data['lon_x']
30    LatX = location_update_floor_georeferencing_data['lat_x']
31    OffsetX = location_update_floor_georeferencing_data['offset_x']
32    LonY = location_update_floor_georeferencing_data['lon_y']
33    LatY = location_update_floor_georeferencing_data['lat_y']
34    OffsetY = location_update_floor_georeferencing_data['offset_y']
35 
36    = longitude * LonX + latitude * LatX + OffsetX
37    = longitude * LonY + latitude * LatY + OffsetY
38    return x, y
39 
40 
41# Plot map image and location update coordinates on top of it
42image = Image.open(map_image)
43plt.imshow(image)
44x, y = wgs84_to_pixels(LOCATION['lon'], LOCATION['lat'])
45plt.scatter(x, y)
46plt.show()
    • Related Articles

    • Sample code

      We supply a .zip file with the X509 certificate for authentication, alongside a sample Python script (referenced below) that illustrates how to connect to the API and obtain information. Please modify it as necessary (such as changing the certificate ...
    • Flutter

      NAOSDK Flutter Plugin In the context of helping our customers and partners who want to develop their application with Flutter and use NAOSDK indoor location-based use cases, we have developed a version of a flutter plugin that makes it easy to embed ...
    • Integration workflow and recommendations

      This page gives useful information for the project management aspect of the integration of the MQTT API. Planning and effort estimation for the integration: Coding effort: from 1 to 2 staff days, integration support : 1 staff day; Testing effort: 1 ...
    • Overview

      We supply a .zip file with the X509 certificate for authentication, alongside a sample Python script (referenced below) that illustrates how to connect to the API and obtain information. Please modify it as necessary (such as changing the certificate ...
    • iOS

      NaoMapSdkFramework provides easy-to-use and powerful NAO Map library iOS. The classes are described below. Installation use_frameworks! # Add this if you are targeting iOS 11+ platform :ios, '11.0' install! 'cocoapods', :deterministic_uuids => false ...