summaryrefslogtreecommitdiff
path: root/platform/ios/demo/Examples/Swift/DrawingAMarkerExample.swift
diff options
context:
space:
mode:
Diffstat (limited to 'platform/ios/demo/Examples/Swift/DrawingAMarkerExample.swift')
-rw-r--r--platform/ios/demo/Examples/Swift/DrawingAMarkerExample.swift38
1 files changed, 38 insertions, 0 deletions
diff --git a/platform/ios/demo/Examples/Swift/DrawingAMarkerExample.swift b/platform/ios/demo/Examples/Swift/DrawingAMarkerExample.swift
new file mode 100644
index 0000000000..5868460061
--- /dev/null
+++ b/platform/ios/demo/Examples/Swift/DrawingAMarkerExample.swift
@@ -0,0 +1,38 @@
+import Mapbox
+
+@objc(DrawingAMarkerExample_Swift)
+
+class DrawingAMarkerExample_Swift: UIViewController, MGLMapViewDelegate {
+ override func viewDidLoad() {
+ super.viewDidLoad()
+
+ let mapView = MGLMapView(frame: view.bounds)
+ mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
+
+ // Set the map’s center coordinate and zoom level.
+ mapView.setCenter(CLLocationCoordinate2D(latitude: 40.7326808, longitude: -73.9843407), zoomLevel: 12, animated: false)
+ view.addSubview(mapView)
+
+ // Set the delegate property of our map view to `self` after instantiating it.
+ mapView.delegate = self
+
+ // Declare the marker `hello` and set its coordinates, title, and subtitle.
+ let hello = MGLPointAnnotation()
+ hello.coordinate = CLLocationCoordinate2D(latitude: 40.7326808, longitude: -73.9843407)
+ hello.title = "Hello world!"
+ hello.subtitle = "Welcome to my marker"
+
+ // Add marker `hello` to the map.
+ mapView.addAnnotation(hello)
+ }
+
+ // Use the default marker. See also: our view annotation or custom marker examples.
+ func mapView(_ mapView: MGLMapView, viewFor annotation: MGLAnnotation) -> MGLAnnotationView? {
+ return nil
+ }
+
+ // Allow callout view to appear when an annotation is tapped.
+ func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool {
+ return true
+ }
+}