在我的应用程序中,我有一个使用OSMDroid的map-activity。我已设法通过Overlay手动添加标记以显示不同的位置,但我想实现一个功能,当您点击双击或长按时将创建标记。 我已经在网上搜索了一些很好的解释,因为我很难理解OSMDroid及其奖金包的文档。
以下是我的相关代码:
public class Map extends Activity{
MapView mapView;
MapController mapController;
ArrayList<OverlayItem> overlayItemArray;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
mapView = (MapView) this.findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
mapView.setMultiTouchControls(true);
mapController = (MapController) mapView.getController();
mapController.setZoom(14);
GeoPoint startPoint = new GeoPoint(58.4109, 15.6216);
mapController.setCenter(startPoint);
// Create an ArrayList with overlays to display objects on map
overlayItemArray = new ArrayList<OverlayItem>();
// Create som init objects
OverlayItem linkopingItem = new OverlayItem("Linkoping", "Sweden",
new GeoPoint(58.4109, 15.6216));
OverlayItem stockholmItem = new OverlayItem("Stockholm", "Sweden",
new GeoPoint(59.3073348, 18.0747967));
// Add the init objects to the ArrayList overlayItemArray
overlayItemArray.add(linkopingItem);
overlayItemArray.add(stockholmItem);
// Add the Array to the IconOverlay
ItemizedIconOverlay<OverlayItem> itemizedIconOverlay = new ItemizedIconOverlay<OverlayItem>(this, overlayItemArray, null);
// Add the overlay to the MapView
mapView.getOverlays().add(itemizedIconOverlay);
}