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
Use the following code snippet to set traffic flow data. Similar to the code in the previous section, we pass the return value of the `flow` method to the `setTraffic` method. There are four values that can be passed to `flow`, and each value would trigger `flow` to return the respective value. The return value of `flow` will then be passed as the argument to `setTraffic`. See the table below for these four values:
50
+
51
+
| | |
52
+
| :-- | :-- |
53
+
| TrafficFlow.NONE | Doesn't display traffic data on the map |
54
+
|TrafficFlow.RELATIVE|Shows traffic data that's relative to the free-flow speed of the road |
55
+
| TrafficFlow.RELATIVE_DELAY | Displays areas that are slower than the average expected delay |
56
+
| TrafficFlow.ABSOLUTE | Shows the absolute speed of all vehicles on the road |
## Show incident traffic data by clicking a feature
41
67
42
68
To obtain the incidents for a specific feature, you can use the code below. When a feature is clicked, the code logic checks for incidents and builds a message about the incident. A message shows up at the bottom of the screen with the details.
43
69
44
-
1.First, you need to edit **res > layout > activity_main.xml**, so that it looks like the one below. Replace the placeholders for `mapcontrol_centerLat`, `mapcontrol_centerLng`, and `mapcontrol_zoom` with your desired values. Recall, the zoom level is a value between 0 and 22.At zoom level 0, the entire world fits on a single tile.
70
+
1. First, you need to edit **res > layout > activity_main.xml**, so that it looks like the one below. You may replace the `mapcontrol_centerLat`, `mapcontrol_centerLng`, and `mapcontrol_zoom` with your desired values. Recall, the zoom level is a value between 0 and 22. At zoom level 0, the entire world fits on a single tile.
@@ -100,6 +127,8 @@ public class MainActivity extends AppCompatActivity {
100
127
101
128
//Wait until the map resources are ready.
102
129
mapControl.getMapAsync(map -> {
130
+
131
+
map.setTraffic(flow(TrafficFlow.RELATIVE));
103
132
map.setTraffic(incidents(true));
104
133
105
134
map.events.add((OnFeatureClick) (features) -> {
@@ -186,40 +215,14 @@ public class MainActivity extends AppCompatActivity {
186
215
}
187
216
```
188
217
189
-
3.Once you incorporate the above code in your application, you'll be able to click on a feature and learn about the traffic incidents for that feature. Depending on the latitude, longitude, and the zoom level values that you selected in your **activity_main.xml** file, you'll see results similar to the following image:
218
+
3. Once you incorporate the above code in your application, you'll be able to click on a feature and see the details of the traffic incidents. Depending on the latitude, longitude, and the zoom level values that you used in your **activity_main.xml** file, you'll see results similar to the following image:
Use the following code snippet to set traffic flow data. Similar to the code in the previous section, we pass the return value of the `flow` method to the `setTraffic` method. There are four values that can be passed to `flow`, and each value would trigger `flow` to return the respective value. The return value of `flow` will then be passed as the argument to `setTraffic`. See the table below for these four values:
207
-
208
-
| | |
209
-
| :-- | :-- |
210
-
| TrafficFlow.NONE | Doesn't display traffic data on the map |
211
-
|TrafficFlow.RELATIVE|Shows traffic data that's relative to the free-flow speed of the road |
212
-
| TrafficFlow.RELATIVE_DELAY | Displays areas that are slower than the average expected delay |
213
-
| TrafficFlow.ABSOLUTE | Shows the absolute speed of all vehicles on the road |
0 commit comments