# Visualize location data ![A sketchnote overview of this lesson](../../../sketchnotes/lesson-13.jpg) > Sketchnote by [Nitya Narasimhan](https://github.com/nitya). Click the image for a larger version. This video gives an overview of Azure Maps with IoT, a service that will be covered in this lesson. [![Azure Maps - The Microsoft Azure Enterprise Location Platform](https://img.youtube.com/vi/P5i2GFTtb2s/0.jpg)](https://www.youtube.com/watch?v=P5i2GFTtb2s) > 🎥 Click the image above to watch the video ## Pre-lecture quiz [Pre-lecture quiz](https://thankful-pond-0eba8f10f.1.azurestaticapps.net/quiz/25) ## Introduction In the last lesson you learned how to get GPS data from your sensors to save to the cloud in a storage container using serverless code. Now you will discover how to visualize those points on an Azure map. You will learn how to create a map on a web page, learn about the GeoJSON data format and how to use it to plot all the captured GPS points on your map. In this lesson we'll cover: * [What is data visualization](#what-is-data-visualization) * [Map services](#map-services) * [Create an Azure Maps resource](#create-an-azure-maps-resource) * [Show a map on a web page](#show-a-map-on-a-web-page) * [The GeoJSON format](#the-geojson-format) * [Plot GPS data on a Map using GeoJSON](#plot-gps-data-on-a-map-using-geojson) > 💁 This lesson will involve a small amount of HTML and JavaScript. If you would like to learn more about web development using HTML and JavaScript, check out [Web development for beginners](https://github.com/microsoft/Web-Dev-For-Beginners). ## What is data visualization Data visualization, as the name suggests, is about visualizing data in ways that make it easier for humans to understand. It is usually associated with charts and graphs, but is any way of pictorially representing data to help humans to not only understand the data better, but help them make decisions. Taking a simple example - back in the farm project you captured soil moisture settings. A table of soil moisture data captured every hour for the 1st June 2021 might be something like the following: | Date | Reading | | ---------------- | ------: | | 01/06/2021 00:00 | 257 | | 01/06/2021 01:00 | 268 | | 01/06/2021 02:00 | 295 | | 01/06/2021 03:00 | 305 | | 01/06/2021 04:00 | 325 | | 01/06/2021 05:00 | 359 | | 01/06/2021 06:00 | 398 | | 01/06/2021 07:00 | 410 | | 01/06/2021 08:00 | 429 | | 01/06/2021 09:00 | 451 | | 01/06/2021 10:00 | 460 | | 01/06/2021 11:00 | 452 | | 01/06/2021 12:00 | 420 | | 01/06/2021 13:00 | 408 | | 01/06/2021 14:00 | 431 | | 01/06/2021 15:00 | 462 | | 01/06/2021 16:00 | 432 | | 01/06/2021 17:00 | 402 | | 01/06/2021 18:00 | 387 | | 01/06/2021 19:00 | 360 | | 01/06/2021 20:00 | 358 | | 01/06/2021 21:00 | 354 | | 01/06/2021 22:00 | 356 | | 01/06/2021 23:00 | 362 | As a human, understanding that data can be hard. It's a wall of numbers without any meaning. As a first step to visualizing this data, it can be plotted on a line chart: ![A line chart of the above data](../../../images/chart-soil-moisture.png) This can be further enhanced by adding a line to indicate when the automated watering system was turned on at a soil moisture reading of 450: ![A line chart of soil moisture with a line at 450](../../../images/chart-soil-moisture-relay.png) This chart shows very quickly not only what the soil moisture levels were, but the points where the watering system was turned on. Charts are not the only tool to visualize data. IoT devices that track weather can have web apps or mobile apps that visualize weather conditions using symbols, such as a cloud symbol for cloudy days, a rain cloud for rainy days and so on. There are a huge number of ways to visualize data, many serious, some fun. ✅ Think about ways you've seen data visualized. Which methods have been the clearest and have allowed you to make decisions fastest? The best visualizations allow humans to humans to make decisions quickly. For example, having a wall of gauges showing all manner of readings from industrial machinery is hard to process, but a flashing red light when something goes wrong allows a human to make a decision. Sometimes the best visualization is a flashing light! When working with GPS data, the clearest visualization can be to plot the data on a map. A map showing delivery trucks for example, can help workers at a processing plant see when trucks will arrive. If this map shows more that just pictures of trucks at their current locations, but gives an idea of the contents of a truck, then the workers at the plant can plan accordingly - if they see a refrigerated truck close by they know to prepare space in a fridge. ## Map services Working with maps is an interesting exercise, and there are many to choose from such as Bing Maps, Leaflet, Open Street Maps, and Google Maps. In this lesson, you will learn about [Azure Maps](https://azure.microsoft.com/services/azure-maps/?WT.mc_id=academic-17441-jabenn) and how they can display your GPS data. ![The Azure Maps logo](../../../images/azure-maps-logo.png) Azure Maps is "a collection of geospatial services and SDKs that use fresh mapping data to provide geographic context to web and mobile applications." Developers are provided with tools to create beautiful, interactive maps that can do things like provide recommended traffic routes, give information about traffic incidents, indoor navigation, search capabilities, elevation information, weather services and more. ✅ Experiment with some [mapping code samples](https://docs.microsoft.com/samples/browse?WT.mc_id=academic-17441-jabenn&products=azure-maps) You can display the maps as a blank canvas, tiles, satellite images, satellite images with roads superimposed, various types of grayscale maps, maps with shaded relief to show elevation, night view maps, and a high contrast map. You can get real-time updates on your maps by integrating them with [Azure Event Grid](https://azure.microsoft.com/services/event-grid/?WT.mc_id=academic-17441-jabenn). You can control the behavior and look of your maps by enabling various controls to allow the map to react to events like pinch, drag, and click. To control the look of your map, you can add layers that include bubbles, lines, polygons, heat maps, and more. Which style of map you implement depends on your choice of SDK. You can access Azure Maps APIs by leveraging its [REST API](https://docs.microsoft.com/javascript/api/azure-maps-rest/?WT.mc_id=academic-17441-jabenn&view=azure-maps-typescript-latest), its [Web SDK](https://docs.microsoft.com/azure/azure-maps/how-to-use-map-control?WT.mc_id=academic-17441-jabenn), or, if you are building a mobile app, its [Android SDK](https://docs.microsoft.com/azure/azure-maps/how-to-use-android-map-control-library?WT.mc_id=academic-17441-jabenn&pivots=programming-language-java-android). In this lesson, you will use the web SDK to draw a map and display your sensor's GPS location's path. ## Create an Azure Maps resource Your first step is to create an Azure Maps account. ### Task - create an Azure Maps resource 1. Run the following command from your Terminal or Command Prompt to create an Azure Maps resource in your `gps-sensor` resource group: ```sh az maps account create --name gps-sensor \ --resource-group gps-sensor \ --accept-tos \ --sku S1 ``` This will create an Azure Maps resource called `gps-sensor`. The tier being used is `S1`, which is a paid tier that includes a range of features, but with a generous amount of calls for free. > 💁 To see the cost of using Azure Maps, check out the [Azure Maps pricing page](https://azure.microsoft.com/pricing/details/azure-maps/?WT.mc_id=academic-17441-jabenn). 1. You will need an API key for the maps resource. Use the following command to get this key: ```sh az maps account keys list --name gps-sensor \ --resource-group gps-sensor \ --output table ``` Take a copy of the `PrimaryKey` value. ## Show a map on a web page Now you can take the next step which is to display your map on a web page. We will use just one `html` file for your small web app; keep in mind that in a production or team environment, your web app will most likely have more moving parts! ### Task - show a map on a web page 1. Create a file called index.html in a folder somewhere on your local computer. Add HTML markup to hold a map: ```html
``` The map will load in the `myMap` `div`. A few styles allow it to span the width and height of the page. > 🎓 a `div` is a section of a web page that can be named and styled. 1. Under the opening `` tag, add an external style sheet to control the map display, and an external script from the Web SDK to manage its behavior: ```html ``` This style sheet contains the settings for how the map looks, and the script file contains code to load the map. Adding this code is similar to including C++ header files or importing Python modules. 1. Under that script, add a script block to launch the map. ```javascript ``` Replace `