Compose一键集成5大地图神器
gd_compose | |
tencent_compose | |
baidu_compose |
repositories {
maven { url = uri("https://mirrors.tencent.com/nexus/repository/maven-public/") }
}
android {
// ...
kotlinOptions {
jvmTarget = '19'
}
dependencies {
// 根据自己项目情况,选择下面其中一种地图
implementation("io.github.TheMelody:gd_compose:<version>") // 高德地图
implementation("io.github.TheMelody:tencent_compose:<version>") // 腾讯地图
implementation("io.github.TheMelody:baidu_compose:<version>") // 百度地图
implementation("io.github.TheMelody:google_compose:<version>") // Google地图 → 未开始
// 华为这个大部分能力需要企业账号才能开通,无法继续其他功能验证,暂时放弃,劝退!
//implementation("io.github.TheMelody:huawei_compose:<version>") // 花瓣地图(Android 7.0+)
}
}
JDK : 19
Gradle : 8.5
Compose BOM:2024.09.03
AndroidStudio建议使用:Android Studio Koala及以上版本
// 地图隐私合规,请在App授权完隐私弹窗协议的第一时间,立即调用
MapUtils#setMapPrivacy
// baidu_compose这个库中,默认使用的是国测局坐标,如想切换请使用:
MapUtils#updateCoordType
// 地图API Key配置 (😂请在AndroidManifest.xml中配置)
//(地图厂商问题,如腾讯的地图SDK在用到定位相关的服务的时候会报:请申请秘钥的提示,无法在代码中直接设置)
// 还是按照地图SDK默认给的配置规则去做吧,暂时无法统一名称进行收拢
// 百度地图api key配置:
<meta-data
android:name="com.baidu.lbsapi.API_KEY"
android:value="自己去百度地图开发者平台申请" />
// 腾讯地图api key配置:
<meta-data
android:name="TencentMapSDK"
android:value="自己去腾讯地图开发者平台申请"/>
// 高德地图api key配置:
<meta-data
android:name="com.amap.api.v2.apikey"
android:value="自己去高德地图开发者平台申请"/>
val cameraPositionState = rememberCameraPositionState {
position = CameraPosition.fromLatLngZoom(LatLng(39.984108,116.307557), 10F)
}
GDMap(
modifier = Modifier.fillMaxSize(),
cameraPositionState = cameraPositionState
){
//这里面放地图覆盖物...
}
val cameraPositionState = rememberCameraPositionState {
position = TXCameraPosition(latLng = LatLng(39.984108,116.307557), zoom = 10F, tilt = 0F, bearing = 0F)
}
TXMap(
modifier = Modifier.fillMaxSize(),
cameraPositionState = cameraPositionState
){
//这里面可以放地图覆盖物...
}
val cameraPositionState = rememberCameraPositionState {
position = BDCameraPosition(LatLng(39.984108,116.307557), 4F, 0f, 0f)
}
BDMap(
modifier = Modifier.fillMaxSize(),
cameraPositionState = cameraPositionState
){
//这里面可以放地图覆盖物...
}
// 高德地图
GDMap(
modifier = Modifier.fillMaxSize(),
properties = MapProperties(/**自行修改参数**/),
uiSettings = MapUiSettings(/**自行修改参数**/)
){
//这里面可以放地图覆盖物...
}
//腾讯地图
TXMap(
modifier = Modifier.fillMaxSize(),
properties = MapProperties(/**自行修改参数**/),
uiSettings = MapUiSettings(/**自行修改参数**/)
){
//这里面可以放地图覆盖物...
}
//百度地图
BDMap(
modifier = Modifier.fillMaxSize(),
properties = MapProperties(/**自行修改参数**/),
uiSettings = MapUiSettings(/**自行修改参数**/)
){
//这里面可以放地图覆盖物...
}
// 只修改内容,不修改容器
MarkerInfoWindowContent(
// ...
title = "我是title",
snippet = "我是snippet"
) { marker ->
Column {
Text(marker.title ?: "", color = Color.Green)
Text(marker.snippet ?: "", color = Color.Red)
// TODO: 如果是百度地图,请使用 marker.getTitleExt() 和 marker.getSnippetExt()
}
}
// 修改整个信息窗(容器及内容)
MarkerInfoWindow(
//...
snippet = "我是一个卖报的小画家(自定义InfoWindow)"
) { marker ->
Card(modifier = Modifier.requiredSizeIn(maxWidth = 88.dp, minHeight = 66.dp)) {
Text(
modifier = Modifier.padding(4.dp),
text = marker.snippet ?: "", color = Color.Red)
// TODO: 如果是百度地图,请使用 marker.getSnippetExt()
}
}
高德地图 | Arc、Circle、ClusterOverlay、GroundOverlay、Marker、MovingPointOverlay、MultiPointOverlay、OpenGLOverlay、Polygon、Polyline、RoutePlanOverlay、TileOverlay |
腾讯地图 | Arc、Circle、ClusterOverlay、GroundOverlay、Marker、MovingPointOverlay、Polygon、Polyline、TileOverlay |
百度地图 | Arc、Circle、ClusterOverlay、GroundOverlay、Marker、MultiPointOverlay、Polygon、Polyline、TileOverlay、RoutePlanOverlay、TextOverlay、TraceOverlay、BM3DBuildOverlay、BM3DModelOverlay、BM3DPrismOverlay |
更多能力,请查阅我们的示例Demo
MIT License
Copyright (c) 2023 被风吹过的夏天
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.