简体   繁体   中英

How to add Custom Map Pins to the Map View on the Apple Watch?

I am beginning to code for the Apple Watch and I am wondering how can I do this:

Thank you!

Apple Interface Guidelines的屏幕截图

First you need to add a map view to your controller (for example InterceController.swift )

Then, you can call these lines in your InterfaceController.swift 's awakeWithContext() or willActivate()

 let location = CLLocationCoordinate2D(
            latitude: 51.530777,
            longitude: -0.139364
        )

 let span = MKCoordinateSpan(
            latitudeDelta: 0.005,
            longitudeDelta: 0.005
       )

 let region = MKCoordinateRegion(center: location, span: span)

 map.setRegion(region)

 map.addAnnotation(location, withImageNamed: "bee.png", centerOffset: CGPoint(x: 0, y: 0))

The key is to call addAnnotation(location: CLLocationCoordinate2D, withImageNamed name: String!, centerOffset offset: CGPoint)

Equivalent Objective-C code:

  CLLocationCoordinate2D location = CLLocationCoordinate2DMake(51.530777, -0.139364);

    MKCoordinateSpan span = MKCoordinateSpanMake(0.005, 0.005);

    MKCoordinateRegion region = MKCoordinateRegionMake(location, span);

    [self.map setRegion:region];

    [self.map addAnnotation:location withImageNamed:@"bee.png" centerOffset:CGPointMake(0, 0)];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM