Tutorial 4 — Drive: Dynamic Marker and Animated Vector Circle
You can view source code for this tutorial here:https://github.com/ba3llc/AltusMappingEngineAndroid/tree/master/Drive
In this tutorial, we’ll build on tutorial 3 and add a vehicle marker, an animated beacon to call attention to its location. Then we’ll smoothly animate the vehicle over the route. This will demonstrate how to animate a marker on a map.
Step 1 - Create a function to add vehicle marker layer
Step 2 - Create a function add a pulsating beacon
Step 3 - In your main activity’s onCreate function, add the vehicle and beacon
Step 4 - Run your application and make sure the vehicle and beacon show up
Step 5 - Create a ValueAnimator
We want to simulate having the vehicle move. We’ll do this by stepping through the routePoint array by ‘animating’ an integer value that we’ll use as index into that array. Each time the index increments, we’ll feed a new coordinate into the mapping engine for the vehicle position, rotation, and the beacon position.
Since this is a lot of changes to a single file, you can simply refer to the file here if you get stuck: https://github.com/ba3llc/AltusMappingEngineAndroid/blob/master/Drive/src/com/example/drive/MainActivity.java
At this point, the project takes on many changes. Make your code look like the following:
When you run your application again, you should see a simulated drive through down-town Raleigh with frequent stops at intersections.
Notes and Things to Try
This is just a simple example of what is possible by combining a raster map layer, a dynamic vector layer, a dynamic marker layer, and an animated vector circle.
Here are some things you can try on your own:
- Try using different line styles, colors, and source maps.
- Try enabling your device’s GPS and feeding coordinates into the mapping engine to show your current location.
You can learn more about the Altus Mapping Engine classes used in this tutorial in the Documentation. If you have any questions about the Altus Mapping Engine, any feature requests or suggestions for improving the Altus Mapping Engine, please send them to [email protected].