2016-12-30 86 views
1

如何使用infowindow標記在android上實現開放式街道地圖?如何使用infowindow標記在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);} 

這是我的代碼和y要添加標記與它就像谷歌地圖

信息窗口

回答

1

最近添加使用標記的樣品。原始源選自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();

1

osmdroid wiki包含一個名爲How to use the osmdroid library指南。它包含一個關於placing icons on the map with a click listener的部分。

基本上你必須創建一個ItemizedOverlayWithFocusOverlayItem組成。每個OverlayItem附帶一個標題,一個描述和當然座標。 ItemizedOverlayWithFocus必須添加到您的MapView

有從wiki頁面的示例:

//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); 
相關問題