ios - swift MapKit 不显示注释引脚

标签 ios swift annotations mapkit

我正在学习 swift 并尝试使用 SwiftyJson 来解析 json 文件并在 map View 中添加注释,但无法在模拟器上显示图钉。我在调试区有一个警告说 Could not inset legal attribution from corner 4。我的代码如下,我已经检查了一些关于这个问题的答案,但仍然无法修复它。非常感谢任何帮助。

        class StationsViewController: UIViewController {

    var stations = [Station]()
    @IBOutlet weak var mapView: MKMapView!
    override func viewDidLoad() {
        super.viewDidLoad()
        mapView.delegate = self //as MKMapViewDelegate
        //mapView.showsUserLocation = YES
        fetchJsonData()
        mapView.addAnnotations(stations)
        }
    func fetchJsonData() {
        // Fetching client list.
        let api_json_url = URL(string:"https://feeds.divvybikes.com/stations/stations.json")
        // Create a URL request with the API address
        let urlRequest = URLRequest(url: api_json_url!)
        // Submit a request to get the JSON data
        //let session = URLSession.shared
        let task = URLSession.shared.dataTask(with: urlRequest) {data,response,error in

            // if there is an error, print the error and do not continue
            if error != nil {
                print("Failed to parse")
                return
            }

            // if there is no error, fetch the json formatted content
            else{
                    let json = JSON(data:data!)
                    if let stationJSONs = json["stationBeanList"].array {
                        for stationJSON in stationJSONs {
                            if let station = Station.from(json: stationJSON) {
                                self.stations.append(station)
                    }
                }
            }
        }// end if
    } // end getDataSession

    task.resume()
    } // end readJsonData function
}

最佳答案

for stationJSON in stationJSONs {
    if let station = Station.from(json: stationJSON) {
        self.stations.append(station)

        let latitude = station["latitude"]
        let longitude = station["longitude"]

        let annotation = MKPointAnnotation()
        let centerCoordinate = CLLocationCoordinate2D(latitude: latitude, longitude)
        annotation.coordinate = centerCoordinate
        annotation.title = "Pass Title here"
        mapView.addAnnotation(annotation)
    }  
}

检查这个。

关于ios - swift MapKit 不显示注释引脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47149643/

相关文章:

ios - Swift 中的 MagicalRecord createEntity 错误

java - 无法同时使用 @NonNull 和 @NonNull 进行注释

xml - hibernate 使用注解或者使用 hibernate 配置文件

python - 如何标记 matplotlib 中两条线之间的百分比变化?

ios - Bitrise:ios-auto-provision 步骤上的双因素身份验证

ios - didReceiveRemoteNotification : fetchCompletionHandler: download freezes

ios - Swift 3 - 如何锁定 iOS 应用程序的方向?

ios - 在 Storyboard上制作一个屏幕,其中 View 在按钮单击时相互替换?

ios - 在 TodayExtension 中使用 MagicalRecord (CoreData)

iphone - Unity 应用程序在第一个场景中崩溃