將Leaflet Android庫集成到現有的Android應用程序中,需要遵循以下步驟:
build.gradle
文件中,添加以下依賴項:dependencies {
implementation 'com.github.mapbox:mapbox-android-sdk:9.6.0'
implementation 'org.apache.leaflet:leaflet-android-library:1.7.1'
}
同步Gradle:點擊Sync Project with Gradle Files
按鈕,讓Gradle同步新的依賴項。
在布局文件中添加地圖視圖:在您的布局文件中,添加一個MapView
控件:
<com.mapbox.geojson.FeatureCollection
android:id="@+id/featureCollection"
android:name="features" />
<com.mapbox.maps.extension.style.layers.generated.symbolLayer
android:id="@+id/symbolLayer"
android:name="symbolLayer"
android:visibility="visible" />
<com.mapbox.maps.extension.style.sources.generated.geoJsonSource
android:id="@+id/geoJsonSource"
android:name="geoJsonSource"
android:visibility="visible" />
<com.mapbox.maps.extension.style.style
android:id="@+id/style"
android:visibility="visible" />
<com.mapbox.maps.plugin.annotation.generated.PointAnnotationManager
android:id="@+id/pointAnnotationManager"
android:visibility="visible" />
<com.mapbox.maps.extension.style.layers.generated.lineLayer
android:id="@+id/lineLayer"
android:name="lineLayer"
android:visibility="visible" />
<com.mapbox.maps.extension.style.sources.generated.vectorSource
android:id="@+id/vectorSource"
android:name="vectorSource"
android:visibility="visible" />
<com.mapbox.maps.plugin.annotation.generated.CircleAnnotationManager
android:id="@+id/circleAnnotationManager"
android:visibility="visible" />
<com.mapbox.maps.extension.style.layers.generated.fillLayer
android:id="@+id/fillLayer"
android:name="fillLayer"
android:visibility="visible" />
<com.mapbox.maps.extension.style.sources.generated.imageSource
android:id="@+id/imageSource"
android:name="imageSource"
android:visibility="visible" />
<com.mapbox.maps.extension.style.layers.generated.backgroundLayer
android:id="@+id/backgroundLayer"
android:name="backgroundLayer"
android:visibility="visible" />
<com.mapbox.maps.extension.style.style
android:id="@+id/style"
android:visibility="visible" />
<com.mapbox.maps.plugin.annotation.generated.PolygonAnnotationManager
android:id="@+id/polygonAnnotationManager"
android:visibility="visible" />
<com.mapbox.maps.extension.style.layers.generated.heatmapLayer
android:id="@+id/heatmapLayer"
android:name="heatmapLayer"
android:visibility="visible" />
<com.mapbox.maps.extension.style.sources.generated.geojsonSource
android:id="@+id/geojsonSource"
android:name="geojsonSource"
android:visibility="visible"