maplibre/maplibre-native
GitHub: maplibre/maplibre-native
MapLibre Native 是一个免费开源的跨平台交互式矢量瓦片地图渲染库,为移动端和桌面应用提供高性能的地图显示能力。
Stars: 2097 | Forks: 559
# MapLibre Native
[](https://codecov.io/github/maplibre/maplibre-native) [](https://slack.openstreetmap.us/)
MapLibre Native 是一个免费且开源的库,用于在各种平台的应用和桌面应用程序中发布地图。得益于 GPU 加速的矢量瓦片渲染,地图的显示速度非常快。
本项目最初是 Mapbox GL Native 的一个分支(fork),后者在 2020 年 12 月切换到了非开源(non-OSS)许可证。更多信息请参见:[`FORK.md`](./FORK.md)。
## 快速入门
### Android
将[最新版本](https://central.sonatype.com/artifact/org.maplibre.gl/android-sdk/versions)的 MapLibre Native Android 作为依赖项添加到您的项目中。
```
dependencies {
...
implementation 'org.maplibre.gl:android-sdk:11.11.0'
...
}
```
将 `MapView` 添加到您的布局 XML 文件中:
```
```
接下来,在 Activity 中初始化地图:
显示代码
```
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.LayoutInflater
import org.maplibre.android.MapLibre
import org.maplibre.android.camera.CameraPosition
import org.maplibre.android.geometry.LatLng
import org.maplibre.android.maps.MapView
import org.maplibre.android.testapp.R
class MainActivity : AppCompatActivity() {
// Declare a variable for MapView
private lateinit var mapView: MapView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Init MapLibre
MapLibre.getInstance(this)
// Init layout view
val inflater = LayoutInflater.from(this)
val rootView = inflater.inflate(R.layout.activity_main, null)
setContentView(rootView)
// Init the MapView
mapView = rootView.findViewById(R.id.mapView)
mapView.getMapAsync { map ->
map.setStyle("https://demotiles.maplibre.org/style.json")
map.cameraPosition = CameraPosition.Builder().target(LatLng(0.0,0.0)).zoom(1.0).build()
}
}
override fun onStart() {
super.onStart()
mapView.onStart()
}
override fun onResume() {
super.onResume()
mapView.onResume()
}
override fun onPause() {
super.onPause()
mapView.onPause()
}
override fun onStop() {
super.onStop()
mapView.onStop()
}
override fun onLowMemory() {
super.onLowMemory()
mapView.onLowMemory()
}
override fun onDestroy() {
super.onDestroy()
mapView.onDestroy()
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
mapView.onSaveInstanceState(outState)
}
}
```
有关更多信息,请参阅 [Android API 文档](https://maplibre.org/maplibre-native/android/api/)或 [Android 示例文档](https://maplibre.org/maplibre-native/android/examples/getting-started/)。
## iOS
您可以在 [Cocoapods](https://cocoapods.org/) 和 [Swift Package Index](https://swiftpackageindex.com/maplibre/maplibre-gl-native-distribution) 上找到 MapLibre Native iOS。您也可以将 MapLibre Native iOS [直接作为依赖项添加到 Xcode](https://maplibre.org/maplibre-native/ios/latest/documentation/maplibre-native-for-ios/gettingstarted/#Add-MapLibre-Native-as-a-dependency)。
MapLibre Native iOS 使用 UIKit。要将其集成到 UIKit 项目中,您可以使用
```
class SimpleMap: UIViewController, MLNMapViewDelegate {
var mapView: MLNMapView!
override func viewDidLoad() {
super.viewDidLoad()
mapView = MLNMapView(frame: view.bounds)
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(mapView)
mapView.delegate = self
}
func mapView(_: MLNMapView, didFinishLoading _: MLNStyle) {
}
}
```
在使用 SwiftUI 时,您需要创建一个包装器(wrapper)。
```
import MapLibre
struct SimpleMap: UIViewRepresentable {
func makeUIView(context _: Context) -> MLNMapView {
let mapView = MLNMapView()
return mapView
}
func updateUIView(_: MLNMapView, context _: Context) {}
}
```
[iOS 文档](https://maplibre.org/maplibre-native/ios/latest/documentation/maplibre/)包含了许多示例以及该库的完整 API。
## Node.js
有一个 [npm 包](https://www.npmjs.com/package/@maplibre/maplibre-gl-native)可用于在 Node.js 项目中使用 MapLibre Native。该项目的源代码[可以在此仓库中找到](https://github.com/maplibre/maplibre-native/tree/main/platform/node)。
## Qt
请查看 [`maplibre/maplibre-native-qt` 仓库](https://github.com/maplibre/maplibre-native-qt)以了解如何将 MapLibre Native 与 Qt 项目集成。
## Compose Multiplatform
[MapLibre Compose](https://github.com/maplibre/maplibre-compose) 为 [Compose Multiplatform](https://www.jetbrains.com/compose-multiplatform/) 支持的各种平台封装了 MapLibre Native。截至 2025 年 8 月,已支持 iOS 和 Android,并部分支持 Web 和桌面平台。
## 其他平台
MapLibre Native 也可以在 [Linux](platform/linux/README.md)、[Windows](platform/windows/README.md) 和 [macOS](platform/macos/README.md) 上构建。
### Core
- [`CONTRIBUTING.md`](CONTRIBUTING.md)
- [GitHub Wiki](https://github.com/maplibre/maplibre-native/wiki):与社区共享信息的低门槛途径
- [Core C++ API 文档](https://maplibre.org/maplibre-native/cpp/api/)(不稳定)
### Android
使用 Android Studio 打开 `platform/android`。
更多信息:[MapLibre Android 开发者指南](https://maplibre.org/maplibre-native/docs/book/platforms/android/index.html)。
### iOS
您需要使用 [Bazel](https://bazel.build/) 来生成 Xcode 项目。安装 [`bazelisk`](https://formulae.brew.sh/formula/bazelisk)(一个用于安装所需 Bazel 版本的包装器)。接下来,使用:
```
bazel run //platform/ios:xcodeproj --@rules_xcodeproj//xcodeproj:extra_common_flags="--//:renderer=metal"
xed platform/ios/MapLibre.xcodeproj
```
生成并打开 Xcode 项目。
更多信息:[MapLibre iOS 开发者指南](https://maplibre.org/maplibre-native/docs/book/platforms/ios/index.html)。
## 其他平台
请查看 [`/platform`](/platform) 并导航至您感兴趣的平台以获取更多信息。

赞助者和支持者:
[](https://opencollective.com/maplibre)
## 许可证
**MapLibre Native** 采用 [BSD 2-Clause 许可证](./LICENSE.md) 授权。
标签:Android, CVE监控, DSL, GPU渲染, iOS, MITM代理, 地图引擎, 矢量瓦片