MapLibre Native is a free and open-source library for publishing maps in your apps and desktop applications on various platforms. Fast displaying of maps is possible thanks to GPU-accelerated vector tile rendering.
This project originated as a fork of Mapbox GL Native, before their switch to a non-OSS license in December 2020. For more information, see: FORK.md
.
Add the latest version of MapLibre Native Android as a dependency to your project.
dependencies {
...
implementation 'org.maplibre.gl:android-sdk:11.5.1'
...
}
Add a MapView
to your layout XML file:
<org.maplibre.android.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
Tip
There are external projects such as Ramani Maps and MapLibre Compose Playground available to intergrate MapLibre Native Android with Compose-based projects.
Next, initialize the map in an activity:
Show code
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)
}
}
For more information, refer to the Android API Documentation, Android Examples Documentation or the MapLibre Native Android README.md
.
You can find MapLibre Native iOS on Cocoapods and on the Swift Package Index. You can also MapLibre Native iOS as a dependency to Xcode directly.
MapLibre Native iOS uses UIKit. To intergrate it with an UIKit project, you can use
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) {
}
}
You need to create a wrapper when using SwiftUI.
import MapLibre
struct SimpleMap: UIViewRepresentable {
func makeUIView(context _: Context) -> MLNMapView {
let mapView = MLNMapView()
return mapView
}
func updateUIView(_: MLNMapView, context _: Context) {}
}
You can also use MapLibreSwiftUI, a wrapper around MapLibre Native iOS that offers a declarative API like SwiftUI.
The iOS Documentation contains many examples and the entire API of the library. You might also want to check out the MapLibre Native iOS README.md
.
There is an npm package for using MapLibre Native in a Node.js project. The source code of this project can be found in this repository.
Please check out the maplibre/maplibre-native-qt
repository to learn how to intergrate MapLibre Native with a Qt project.
MapLibre Native can also be built on Linux, Windows and macOS.
Note
This section is only relevant for people who want to contribute to MapLibre Native.
MapLibre Native has at its core a C++ library. This is where the bulk of development is currently happening.
To get started with the code base, you need to clone the the repository including all its submodules.
All contributors use pull requests from a private fork. Fork the project. Then run:
git clone --recurse-submodules [email protected]:<YOUR NAME>/maplibre-native.git
git remote add origin https://github.com/maplibre/maplibre-native.git
Check out issues labelled as a good first issue.
CONTRIBUTING.md
- MapLibre Native Markdown Book: architectural notes
- GitHub Wiki: low-friction way to share information with the community
- Core C++ API Documentation (unstable)
Open platform/android
with Android Studio.
More information: platform/android/DEVELOPING.md
.
You need to use Bazel to generate an Xcode project. Install bazelisk
(a wrapper that installs the required Bazel version). Next, use:
bazel run //platform/ios:xcodeproj --@rules_xcodeproj//xcodeproj:extra_common_flags="--//:renderer=metal"
xed platform/ios/MapLibre.xcodeproj
To generate and open the Xcode project.
More information: platform/android/CONTRIBUTING.md
.
See /platform
and navigate to the platform you are interested in for more information.
Join the #maplibre-native
Slack channel at OSMUS. Get an invite at https://slack.openstreetmap.us/
Thanks to our sponsors, we are able to award bounties to developers making contributions toward certain bounty directions. To get started doing bounties, refer to the step-by-step bounties guide.
We thank everyone who supported us financially in the past and special thanks to the people and organizations who support us with recurring donations!
Read more about the MapLibre Sponsorship Program at https://maplibre.org/sponsors/.
Gold:
Silver:
Backers and Supporters:
MapLibre Native is licensed under the BSD 2-Clause License.