Android

From BA3 Mapping Engine Wiki
Jump to: navigation, search

Contents

Android Tutorials

Dynamic Markers

Dynamic markers can be positioned, rotated, animated, added, and removed. Images for these markers can be set and re-set any time. This allows you to achieve animations, blinking, and other 'dynamic' marker operations. Let's assume you have an instance of us.ba3.me.MapView named mapView that has been added to an activity.

Implement the DynamicMarkerMapDelegate Interface

Have your Activity (or other map view container) implement the DynamicMarkerMapDelegate interface. This allows you to respond to tap events on the marker. This is only required if you want to respond to tap events.

public class MainActivity extends Activity implements us.ba3.me.markers.DynamicMarkerMapDelegate {
//....other code...
}

Implement the DynamicMarkerMapDelegate interface methods:

@Override
public void tapOnMarker(String arg0, String arg1, PointF arg2, PointF arg3) {
     Log.e("Marker", "Marker tapped");
}

Add a Dynamic Marker Layer

DynamicMarkerMapInfo mapInfo = new DynamicMarkerMapInfo();
mapInfo.name = "Markers";
mapInfo.zOrder = 3;
mapInfo.hitTestingEnabled = true;
mapInfo.delegate=this;
mapView.addMapUsingMapInfo(mapInfo);

Note: hitTestingEnabled is set to true because we want to respond to tap events. If you don't need that, set it to false.

Add Dynamic Markers

This code assumes you have 32x32 pixel image as a resource named bluedot.png.

DynamicMarker marker = new DynamicMarker();
marker.name = "marker1";
marker.setImage(loadBitmap("bluedot.png"), false);
marker.anchorPoint = new PointF(16,16);
marker.location.longitude = -78.6389;
marker.location.latitude = 35.7719;
mapView.addDynamicMarkerToMap("Markers", marker);

When you run your application and tap on a marker you should output like this in the console:

06-30 14:16:20.950: I/me(5185): Altus: TapGestureHandler testing against 1 markers.
06-30 14:16:20.950: E/Marker(5185): Marker tapped
06-30 14:16:24.794: I/me(5185): Altus: TapGestureHandler testing against 1 markers.
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox