You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This tutorial guides you through the process of importing a GeoJSON file of location data into the Azure Maps Android SDK. In this tutorial, you learn how to:
17
18
18
19
> [!div class="checklist"]
20
+
>
19
21
> * Add Azure Maps to an Android application.
20
22
> * Create a data source and load in a GeoJSON file from a local file or the web.
21
23
> * Display the data on the map.
22
24
> * Interact with the data on the maps to view its details.
23
25
24
26
## Prerequisites
25
27
26
-
1. Complete the [Quickstart: Create an Android app](quick-android-map.md). This tutorial extends the code used in that quickstart.
27
-
2. Download the [Sample Points of Interest](https://github.com/Azure-Samples/AzureMapsCodeSamples/blob/master/Static/data/geojson/SamplePoiDataSet.json) GeoJSON file.
28
+
1. Complete the [Quickstart: Create an Android app]. This tutorial extends the code used in that quickstart.
29
+
2. Download the [Sample Points of Interest] GeoJSON file.
28
30
29
31
### Import GeoJSON data from web or assets folder
30
32
31
33
Most GeoJSON files wrap all data within a `FeatureCollection`. With this scenario in mind, if the GeoJSON files are loaded into the application as a string, they can be passed into the feature collection's static `fromJson` method, which deserializes the string into a GeoJSON `FeatureCollection` object that can be added to the map.
32
34
33
35
The following steps show you how to import a GeoJSON file into the application and deserialize it as a GeoJSON `FeatureCollection` object.
34
36
35
-
1. Complete the [Quickstart: Create an Android app](quick-android-map.md) as the following steps build on top of this application.
37
+
1. Complete the [Quickstart: Create an Android app] as the following steps build on top of this application.
36
38
2. In the project panel of Android studio, right-click on the **app** folder and go to `New > Folder > Assets Folder`.
37
-
3. Drag and drop the [Sample Points of Interest](https://github.com/Azure-Samples/AzureMapsCodeSamples/blob/master/Static/data/geojson/SamplePoiDataSet.json) GeoJSON file into the assets folder.
39
+
3. Drag and drop the [Sample Points of Interest] GeoJSON file into the assets folder.
38
40
39
41
::: zone pivot="programming-language-java-android"
40
42
41
-
4. Go into the **MainActivity.java** file and add the following code inside the callback for the `mapControl.onReady` event, inside the `onCreate` method. This code loads the **SamplePoiDataSet.json** file from the assets folder into a data source using `importDataFromUrl` method and then adds it to the map.
43
+
4. Go into the _MainActivity.java_ file and add the following code inside the callback for the `mapControl.onReady` event, inside the `onCreate` method. This code loads the _SamplePoiDataSet.json_ file from the assets folder into a data source using `importDataFromUrl` method and then adds it to the map.
42
44
43
45
```java
44
46
//Create a data source and add it to the map.
@@ -55,7 +57,7 @@ map.sources.add(source);
55
57
56
58
::: zone pivot="programming-language-kotlin"
57
59
58
-
4. Go into the **MainActivity.kt** file and add the following code inside the callback for the `mapControl.onReady` event, inside the `onCreate` method. This code loads the **SamplePoiDataSet.json** file from the assets folder into a data source using `importDataFromUrl` method and then adds it to the map.
60
+
4. Go into the _MainActivity.kt_ file and add the following code inside the callback for the `mapControl.onReady` event, inside the `onCreate` method. This code loads the _SamplePoiDataSet.json_ file from the assets folder into a data source using `importDataFromUrl` method and then adds it to the map.
59
61
60
62
```kotlin
61
63
//Create a data source and add it to the map.
@@ -70,7 +72,7 @@ map.sources.add(source);
70
72
71
73
::: zone-end
72
74
73
-
5. Using the code to load the GeoJSON data a data source, we now need to specify how that data should be displayed on the map. There are several different rendering layers for point data; [Bubble layer](map-add-bubble-layer-android.md), [Symbol layer](how-to-add-symbol-to-android-map.md), and [Heat map layer](map-add-heat-map-layer-android.md) are the most commonly used layers. Add the following code to render the data in a bubble layer in the callback for the `mapControl.onReady` event after the code for importing the data.
75
+
5. Using the code to load the GeoJSON data a data source, we now need to specify how that data should be displayed on the map. There are several different rendering layers for point data; [Bubble layer], [Symbol layer], and [Heat map layer] are the most commonly used layers. Add the following code to render the data in a bubble layer in the callback for the `mapControl.onReady` event after the code for importing the data.
74
76
75
77
::: zone pivot="programming-language-java-android"
76
78
@@ -92,8 +94,8 @@ map.layers.add(layer)
92
94
93
95
::: zone-end
94
96
95
-
6. In the project panel of Android studio, right-click on the **layout** folder under the path `app > res > layout` and go to `New > File`. Create a new file called **popup_text.xml**.
96
-
7. Open the **popup_text.xml** file. If the file opens in a designer view, right-click on the screen and select "Go to XML". Copy and paste the following XML into this file. This XML creates a simple layout that can be used with a popup and contains a text view.
97
+
6. In the project panel of Android studio, right-click on the **layout** folder under the path `app > res > layout` and go to `New > File`. Create a new file called _popup_text.xml_.
98
+
7. Open the _popup_text.xml_ file. If the file opens in a designer view, right-click on the screen and select **Go to XML**. Copy and paste the following XML into this file. This XML creates a simple layout that can be used with a popup and contains a text view.
97
99
98
100
```xml
99
101
<?xml version="1.0" encoding="utf-8"?>
@@ -120,7 +122,7 @@ map.layers.add(layer)
120
122
121
123
::: zone pivot="programming-language-java-android"
122
124
123
-
8. Go back into the **MainActivity.java** file and after the code for the bubble layer, add the following code to create a reusable popup.
125
+
8. Go back into the _MainActivity.java_ file and after the code for the bubble layer, add the following code to create a reusable popup.
124
126
125
127
```java
126
128
//Create a popup and add it to the map.
@@ -135,7 +137,7 @@ popup.close();
135
137
136
138
::: zone pivot="programming-language-kotlin"
137
139
138
-
8. Go back into the **MainActivity.kt** file and after the code for the bubble layer, add the following code to create a reusable popup.
140
+
8. Go back into the _MainActivity.kt_ file and after the code for the bubble layer, add the following code to create a reusable popup.
139
141
140
142
```kotlin
141
143
//Create a popup and add it to the map.
@@ -148,7 +150,7 @@ popup.close()
148
150
149
151
::: zone-end
150
152
151
-
9. Add the following code to attach a click event to the bubble layer. When a bubble in the bubble layer is tapped, the event will fire and retrieve some details from the properties of the selected feature, create a view using the **popup_text.xml** layout file, pass it in as content into the popup, then show the popup at the features position.
153
+
9. Add the following code to attach a `click` event to the bubble layer. When a bubble in the bubble layer is tapped, the event fires and retrieves details from the properties of the selected feature, create a view using the _popup_text.xml_ layout file, pass it in as content into the popup, then show the popup at the features position.
152
154
153
155
::: zone pivot="programming-language-java-android"
154
156
@@ -250,16 +252,27 @@ Take the following steps to clean up the resources from this tutorial:
250
252
To see more code examples and an interactive coding experience:
0 commit comments