Skip to content

Repository files navigation

MapKit SDK for MapConductor iOS

Description

MapConductor provides a unified API for iOS SwiftUI. You can use Apple MapKit with SwiftUI, but you can also switch to other Maps SDKs (such as MapLibre, Mapbox, and so on), anytime. Even using the wrapper API, you can still access the native MapKit view if you want.

Setup

https://mapconductor.com/setup/ios/mapkit/

API key

No API key. MapKit is Apple's own framework and authenticates through your app's provisioning. (MapKit JS, used by the web SDK, does need a token — that is a different product.)

Usage

import SwiftUI
import MapConductorCore
import MapConductorForMapKit
structMapView:View{@StateObjectprivatevarmapViewState=MapKitViewState(
cameraPosition:MapCameraPosition(
position:GeoPoint(latitude:35.6762, longitude:139.6503),
zoom:2))@StateprivatevarselectedMarker:MarkerState?=nilletcenter=GeoPoint(latitude:35.6762, longitude:139.6503)varbody:someView{MapKitMapView(state: mapViewState){Marker(
position: center,
icon:DefaultMarkerIcon(label:"Tokyo"),
onClick:{ state in selectedMarker = state })iflet selected = selectedMarker {InfoBubble(marker: selected){Text("Hello, world!")}}}}}

Components

MapKitMapView [docs]

structMapExample:View{@StateObjectprivatevarmapViewState=MapKitViewState(
cameraPosition:MapCameraPosition(
position:GeoPoint(latitude:37.422198, longitude:-122.085377),
zoom:17,
tilt:60,
bearing:30))varbody:someView{MapKitMapView(state: mapViewState)}}


Marker [docs]

structMarkerExample:View{@StateprivatevarmarkerState=MarkerState(
position:GeoPoint(latitude:35.6762, longitude:139.6503),
icon:DefaultMarkerIcon(label:"Tokyo"),
onClick:{ state in state.animate(.bounce)})varbody:someView{MapKitMapView(state: mapViewState){Marker(state: markerState)}}}


InfoBubble [docs]

structInfoBubbleExample:View{@StateprivatevarselectedMarker:MarkerState?=nil@StateprivatevarmarkerState=MarkerState(
position:GeoPoint(latitude:35.6762, longitude:139.6503),
onClick:{[self] state in selectedMarker = state })varbody:someView{MapKitMapView(state: mapViewState){Marker(state: markerState)iflet selected = selectedMarker {InfoBubble(marker: selected){Text("Hello, world!")}}}}}


Circle [docs]

structCircleExample:View{varbody:someView{MapKitMapView(state: mapViewState){Circle(
center:GeoPoint(latitude:35.6762, longitude:139.6503),
radiusMeters:50,
fillColor:UIColor.blue.withAlphaComponent(0.5),
onClick:{ state in
state.fillColor =UIColor.red.withAlphaComponent(0.5)})}}}


Polyline [docs]

structPolylineExample:View{varbody:someView{MapKitMapView(state: mapViewState){Polyline(
points: airports,
strokeColor:UIColor.blue.withAlphaComponent(0.5),
geodesic:true)}}}


Polygon [docs]

structPolygonExample:View{varbody:someView{MapKitMapView(state: mapViewState){Polygon(
points: goryokaku,
strokeColor:UIColor.red.withAlphaComponent(0.5),
fillColor:UIColor.red.withAlphaComponent(0.7))}}}


Polygon Hole

structPolygonHoleExample:View{varbody:someView{MapKitMapView(state: mapViewState){Polygon(
points: outerPoints,
holes:[innerPoints1, innerPoints2],
fillColor:UIColor(red:0.47, green:0.47, blue:0.50, alpha:0.8),
strokeColor:UIColor.red,
strokeWidth:2)}}}


GroundImage [docs]

structGroundImageExample:View{varbody:someView{MapKitMapView(state: mapViewState){GroundImage(
bounds:GeoRectBounds(
southWest:GeoPoint.fromLatLong(...),
northEast:GeoPoint.fromLatLong(...)),
image: uiImage,
opacity:0.5)}}}

Releases

Packages

Contributors

Languages