Mapkit多个注释

时间:2018-12-05 15:53:06

标签: annotations location mapkit

我在添加注释时遇到了一些问题,我目前正在制作一个显示您附近所有披萨店的应用程序。我知道如何显示当前位置,但是我需要MapKit的帮助。我想显示披萨的地方,但我也希望它打印名称和电话号码(以Xcode格式)。我需要添加哪些代码行?

1 个答案:

答案 0 :(得分:1)

如何添加一个地图注释:

let annotation = MKPointAnnotation()
annotation.coordinate = CLLocationCoordinate2D(latitude: 10.0, longitude: 59.0)
annotation.title = "Pizza Place"
annotation.subtitle = "Phone: 0012345678"
map.addAnnotation(annotation)

添加多个Pizza Place注释的功能:

func addPizzaPlacesToMap(places: [PizzaPlace]) {

    // Remove all annotations from map
    self.map.removeAnnotations(self.map.annotations)

    // Loop trough all your pizza places and add them to the map
    for place in places {
        let annotation = MKPointAnnotation()
        annotation.title = place.name
        annotation.subtitle = place.phone
        annotation.coordinate = place.coordinate
        self.map.addAnnotation(anno)
    }

}