iOS Mapbox注释未打开 [英] iOS Mapbox annotation not opening

查看:78
本文介绍了iOS Mapbox注释未打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是iOS开发人员的新手,我正在学习Swift的使用iOS MapBox SDK的第一步"(

Fairly new to iOS dev and I'm following the "first steps with the iOS MapBox SDK" tutorial for Swift (https://www.mapbox.com/help/first-steps-ios-sdk/). Things were fine with displaying the map, custom style, and adding an annotation. But then encountered an issue when trying to interact with the annotation to display its title and subtitle.

print("allow") print("tap on callout")似乎从未被调用过.甚至mapView.selectAnnotation(point, animated: true) 也不做任何事情(也没有它也不做任何事)

The print("allow") print("tap on callout") don't seem to ever get called. Even mapView.selectAnnotation(point, animated: true) doesn't do anything (and it wasn't doing anything without it either)

使用xCode 8.0,MacOS Sierra,Swift 3,iOS 10

Using xCode 8.0, MacOS Sierra, Swift 3, iOS 10

我现在有点笨了,任何建议都将不胜感激

I'm a bit clueless now, any advice would be appreciated

预先感谢

ViewController.swift:

import UIKit
import Mapbox
class ViewController: UIViewController{

    @IBOutlet var mapView: MGLMapView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let point = MGLPointAnnotation()
        point.coordinate = CLLocationCoordinate2D(latitude: 46.082666, longitude:7.508510)
        point.title = "Title"
        point.subtitle = "Subtitle"
        mapView.addAnnotation(point)
        mapView.selectAnnotation(point, animated: true)
        print("add annotation");

    }

    // Return `nil` here to use the default marker.
    func mapView(mapView: MGLMapView, viewForAnnotation annotation: MGLPointAnnotation) -> MGLAnnotationView? {
        print("default marker")
        return nil
    }

    // Allow callout view to appear when an annotation is tapped.
    func mapView(mapView: MGLMapView, annotationCanShowCallout annotation: MGLPointAnnotation) -> Bool {
        print("allow")
        return true
    }
    func mapView(mapView: MGLMapView, tapOnCalloutForAnnotation annotation: MGLAnnotation) {
        print("tap on callout")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

屏幕截图:注解显示了应该但不能与之交互的位置

推荐答案

此代码指出的位置

class ViewController: UIViewController{

尚未配置为地图的委托.该行应改为

It hasn't been configured to be the map's delegate. This line should instead be

class ViewController: UIViewController, MGLMapViewDelegate {

根据第一步指南中的规定

这篇关于iOS Mapbox注释未打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆