如何在 android 上使用标记上的信息窗口实现开放式街道地图?
How to implement open street map on android with infowindow on markers?
如何在 android 上使用标记上的信息窗口实现开放式街道地图?
OpenStreetMapTileProviderConstants.setUserAgentValue(BuildConfig.APPLICATION_ID);
openStreetMap = (MapView)findViewById(R.id.openmapview);
openStreetMap.setBuiltInZoomControls(true);
openStreetMapController = openStreetMap.getController();
openStreetMapController.setZoom(16);
openStreetMap.setMultiTouchControls(true);
GeoPoint initialLocation = new GeoPoint(lat , lng);
centerMap(initialLocation);
addLocation(lat ,lng , R.drawable.marker);}
这是我的代码,你想用它的 infoWindows 添加标记,比如 googleMaps
osmdroid wiki contains a guide called How to use the osmdroid library. It contains a section about placing icons on the map with a click listener.
基本上你必须创建一个由 OverlayItem
组成的 ItemizedOverlayWithFocus
。每个 OverlayItem
都带有标题、描述,当然还有坐标。 ItemizedOverlayWithFocus
必须添加到您的 MapView
。
维基页面中有示例:
//your items
ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
items.add(new OverlayItem("Title", "Description", new GeoPoint(0.0d,0.0d))); // Lat/Lon decimal degrees
//the overlay
ItemizedOverlayWithFocus<OverlayItem> mOverlay = new ItemizedOverlayWithFocus<OverlayItem>(items,
new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
@Override
public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
//do something
return true;
}
@Override
public boolean onItemLongPress(final int index, final OverlayItem item) {
return false;
}
});
mOverlay.setFocusItemsOnTap(true);
mMapView.getOverlays().add(mOverlay);
最近添加了一个使用标记的样本。原文出处来自osmbonuspack's tutorial
样本位于here
基本代码是这样的
GeoPoint startPoint = new GeoPoint(38.8977, -77.0365); //white house
Marker startMarker = new Marker(mMapView);
startMarker.setPosition(startPoint);
startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
startMarker.setIcon(getResources().getDrawable(R.drawable.icon));
startMarker.setTitle("White House");
startMarker.setSnippet("The White House is the official residence and principal workplace of the President of the United States.");
startMarker.setSubDescription("1600 Pennsylvania Ave NW, Washington, DC 20500");
mMapView.getOverlays().add(startMarker);
mMapView.invalidate();
如何在 android 上使用标记上的信息窗口实现开放式街道地图?
OpenStreetMapTileProviderConstants.setUserAgentValue(BuildConfig.APPLICATION_ID);
openStreetMap = (MapView)findViewById(R.id.openmapview);
openStreetMap.setBuiltInZoomControls(true);
openStreetMapController = openStreetMap.getController();
openStreetMapController.setZoom(16);
openStreetMap.setMultiTouchControls(true);
GeoPoint initialLocation = new GeoPoint(lat , lng);
centerMap(initialLocation);
addLocation(lat ,lng , R.drawable.marker);}
这是我的代码,你想用它的 infoWindows 添加标记,比如 googleMaps
osmdroid wiki contains a guide called How to use the osmdroid library. It contains a section about placing icons on the map with a click listener.
基本上你必须创建一个由 OverlayItem
组成的 ItemizedOverlayWithFocus
。每个 OverlayItem
都带有标题、描述,当然还有坐标。 ItemizedOverlayWithFocus
必须添加到您的 MapView
。
维基页面中有示例:
//your items
ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
items.add(new OverlayItem("Title", "Description", new GeoPoint(0.0d,0.0d))); // Lat/Lon decimal degrees
//the overlay
ItemizedOverlayWithFocus<OverlayItem> mOverlay = new ItemizedOverlayWithFocus<OverlayItem>(items,
new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
@Override
public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
//do something
return true;
}
@Override
public boolean onItemLongPress(final int index, final OverlayItem item) {
return false;
}
});
mOverlay.setFocusItemsOnTap(true);
mMapView.getOverlays().add(mOverlay);
最近添加了一个使用标记的样本。原文出处来自osmbonuspack's tutorial
样本位于here
基本代码是这样的
GeoPoint startPoint = new GeoPoint(38.8977, -77.0365); //white house
Marker startMarker = new Marker(mMapView);
startMarker.setPosition(startPoint);
startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
startMarker.setIcon(getResources().getDrawable(R.drawable.icon));
startMarker.setTitle("White House");
startMarker.setSnippet("The White House is the official residence and principal workplace of the President of the United States.");
startMarker.setSubDescription("1600 Pennsylvania Ave NW, Washington, DC 20500");
mMapView.getOverlays().add(startMarker);
mMapView.invalidate();