คู่มือการเชื่อมต่อ
เพิ่มแผนที่ MapScale ใน iOS
แสดง tile ของ MapScale ในแอป Swift iOS ด้วย MapLibre Native
เริ่มต้น
ติดตั้ง MapLibre Native
เพิ่ม MapLibre Native ด้วย Swift Package Manager ใน Xcode
https://github.com/maplibre/maplibre-nativeอนุญาต network access
MapScale ใช้ HTTPS ดังนั้นแอปทั่วไปไม่ต้องเพิ่ม App Transport Security exception
สร้าง SwiftUI wrapper
Wrapper นี้สร้าง native map view และโหลด style ของ MapScale
import MapLibre
import SwiftUI
struct MapScaleView: UIViewRepresentable {
let key = "pk_test_your_key_here"
func makeUIView(context: Context) -> MLNMapView {
let url = URL(string: "https://api.mapscale.io/styles/v1/streets?key=\(key)")!
let map = MLNMapView(frame: .zero, styleURL: url)
map.setCenter(CLLocationCoordinate2D(latitude: 13.7563, longitude: 100.5018), zoomLevel: 11, animated: false)
return map
}
func updateUIView(_ uiView: MLNMapView, context: Context) {}
}