如何使用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);}
这是我的代码,你想添加标记,如googleMaps的infoWindows
答案 0 :(得分:2)
最近添加了使用标记的样本。原始来源是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 :(得分:1)
osmdroid wiki包含一个名为How to use the osmdroid library的指南。它包含有关placing icons on the map with a click listener。
的部分基本上,您必须创建一个由 <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapse_toolbar"
android:layout_width="match_parent"
app:titleEnabled="false"
android:layout_height="250dp"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
//your image view under toolbar
<ImageView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/test"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="100dp"
android:gravity="top"
android:minHeight="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleMarginTop="15dp" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
app:tabIndicatorColor="@color/colorAccent" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
组成的ItemizedOverlayWithFocus
。每个OverlayItem
都带有标题,描述和当然坐标。必须将OverlayItem
添加到您的ItemizedOverlayWithFocus
。
维基页面有一个例子:
MapView