Skip to content

TheMelody/OmniMap-Compose

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OmniMap Compose 🗺

LICENSE issues forks stars 小专栏 稀土掘金 知乎 CSDN

Compose一键集成5大地图神器

集成

gd_composeMaven Central
tencent_composeMaven Central
baidu_composeMaven Central
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.06.00
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="自己去高德地图开发者平台申请"/>

用法

  • 1、添加一个高德地图
val cameraPositionState = rememberCameraPositionState {
    position = CameraPosition.fromLatLngZoom(LatLng(39.984108,116.307557), 10F)
}
GDMap(
    modifier = Modifier.fillMaxSize(),
    cameraPositionState = cameraPositionState
){
    //这里面放地图覆盖物...
}
  • 2、添加一个腾讯地图
val cameraPositionState = rememberCameraPositionState {
   position =  TXCameraPosition(latLng = LatLng(39.984108,116.307557), zoom = 10F, tilt = 0F, bearing = 0F)
}
TXMap(
    modifier = Modifier.fillMaxSize(),
    cameraPositionState = cameraPositionState
){
    //这里面可以放地图覆盖物...
}
  • 3、添加一个百度地图
val cameraPositionState = rememberCameraPositionState {
    position = BDCameraPosition(LatLng(39.984108,116.307557), 4F, 0f, 0f)
}
BDMap(
    modifier = Modifier.fillMaxSize(),
    cameraPositionState = cameraPositionState
){
    //这里面可以放地图覆盖物...
}
  • 4、配置地图
// 高德地图
GDMap(
    modifier = Modifier.fillMaxSize(),
    properties = MapProperties(/**自行修改参数**/),
    uiSettings  = MapUiSettings(/**自行修改参数**/)
){
    //这里面可以放地图覆盖物...
}

//腾讯地图
TXMap(
    modifier = Modifier.fillMaxSize(),
    properties = MapProperties(/**自行修改参数**/),
    uiSettings  = MapUiSettings(/**自行修改参数**/)
){
    //这里面可以放地图覆盖物...
}

//百度地图
BDMap(
    modifier = Modifier.fillMaxSize(),
    properties = MapProperties(/**自行修改参数**/),
    uiSettings  = MapUiSettings(/**自行修改参数**/)
){
    //这里面可以放地图覆盖物...
}
  • 5、自定义Marker覆盖物的InfoWindow
// 只修改内容,不修改容器
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()
    }
}
  • 6、已支持的覆盖物
高德地图 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

License

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.

About

🔥🔥🔥Compose一键集成5大地图平台地图

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages