Skip to content

Commit 5cf9cf2

Browse files
authored
Merge pull request #2023 from arduino/benjamindannegard/advanced-map-widget-featured-page
[IoT Cloud] Added Advanced map widget featured page
2 parents e4a92b6 + 0419abe commit 5cf9cf2

File tree

6 files changed

+112
-0
lines changed

6 files changed

+112
-0
lines changed
Loading
Loading
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
---
2+
title: Advanced Map Widget
3+
description: Learn how to use the advanced map widget, which allows you to track a things location in real time or during a specific time period.
4+
author: Benjamin Dannegård
5+
tags: [Arduino Cloud, Map, GPS, Location]
6+
---
7+
8+
The **advanced map widget** is used to track the location of a cloud Thing and draw a path between the different logged points. You can track GPS locations in real time or chose a specific time frame for location tracking. The look of the tracks between points and map pin can also be customized.
9+
10+
![The advanced map widget.](assets/world-map.gif)
11+
12+
This widget can be added onto existing projects (if you are already tracking location), and is particularly interesting to use in projects such as:
13+
- Weather stations,
14+
- Environmental data stations,
15+
- Monitoring fleets,
16+
- Any project requiring localization of devices,
17+
- Various science projects where location tracking is needed.
18+
19+
## Hardware & Software Needed
20+
21+
- [Arduino Cloud](https://app.arduino.cc/).
22+
- Cloud compatible boards, [see full list](https://docs.arduino.cc/arduino-cloud/guides/overview#compatible-hardware).
23+
24+
***In this tutorial, we use the [MKR WiFi 1010](/hardware/mkr-wifi-1010) and [MKR GPS Shield](/hardware/mkr-gps-shield) for tracking latitude and longitude. This is not a requirement, you can use any board for this tutorial.***
25+
26+
## Setup & Configuration
27+
28+
To use the advanced map widget, you will need to set up a Thing and a variable that you want to track. This needs to be a `Location` type variable, it will be declared as a `CloudLocation` variable.
29+
30+
***If you are unfamiliar with how to set up a Thing and variables, head on over to the [Getting Started with the Arduino Cloud](/arduino-cloud/guides/overview) article.***
31+
32+
**1.** Head on over to the **"Dashboards"** in the Arduino Cloud, and create a new dashboard (or use an existing dashboard).
33+
34+
**2.** Add a new **"Advanced Map Widget"**, selecting it from the list of available widgets.
35+
36+
**3.** Link the location variable you want to track.
37+
38+
![Link variables.](assets/select-variable.png)
39+
40+
**4.** After selection, your variables will appear in the right panel, with a number of configuration options. You can for example choose how the track between logged locations will be represented (line, spline, spline area, line area and bar). You can also change the icon of the pin on the map.
41+
42+
![Advanced map widget configuration.](assets/widget-config.png)
43+
44+
**5.** Click on **"Done"** when finished selecting the variable. If your board is connected and is sending data to the Cloud, you will see the widget's location data update frequently.
45+
46+
## Example Code
47+
48+
The sketch of your project does not require much complexity. In your automatically generated code, simply add the location tracking code inside of the loop. We are using the [Arduino_MKRGPS](https://www.arduino.cc/reference/en/libraries/arduino_mkrgps/) library. We only needed to add these following lines to the loop to track the things location and send it to the advanced map widget:
49+
50+
```arduino
51+
if (GPS.available()) {
52+
// read GPS values
53+
float latitude = GPS.latitude();
54+
float longitude = GPS.longitude();
55+
advancedMap = Location(latitude, longitude);
56+
}
57+
```
58+
59+
The full sketch used is found below:
60+
61+
```arduino
62+
#include <Arduino_MKRGPS.h>
63+
#include "thingProperties.h"
64+
65+
void setup() {
66+
Serial.begin(9600);
67+
delay(1500);
68+
69+
initProperties();
70+
71+
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
72+
73+
setDebugMessageLevel(2);
74+
ArduinoCloud.printDebugInfo();
75+
}
76+
77+
void loop() {
78+
ArduinoCloud.update();
79+
if (GPS.available()) {
80+
// read GPS values
81+
float latitude = GPS.latitude();
82+
float longitude = GPS.longitude();
83+
advancedMap = Location(latitude, longitude);
84+
}
85+
}
86+
```
87+
88+
## Usage
89+
90+
With the widget set up, let's explore some of its features.
91+
92+
### Location Tracking
93+
94+
When tracking the location with the "Live" setting the current location of the device will be marked with a pin, then a track will be drawn between its previous location and its current location.
95+
96+
![View values.](assets/location-tracking.gif)
97+
98+
Picking one of the other time frame options will show the locations of the device during that specific time frame.
99+
100+
### Specific Time Period
101+
102+
To see a specific time period, click on the calendar icon, where you can select the starting & end time & date.
103+
104+
![Select time & date.](assets/set-time-frame.png)
105+
106+
## Limitations
107+
108+
- The advanced map widget only supports the use of the `CloudLocation` variable.
109+
110+
## Summary
111+
112+
The advanced map widget can be used for **any** project that includes location tracking. It is perfect for scientific projects when monitoring the location of the cloud Thing over time is needed.

0 commit comments

Comments
 (0)