2016-04-01 20 views
1

iOSでの開発が始まったところです。もし問題が簡単ではないと思われる場合は、ごめんなさい:Mapbox iOS SDK 3.1注釈吹き出しをつける方法

APIからSwiftyJSON経由でいくつかのマーカー/注釈を読み込んでMapbox MapViewに表示します。アノテーションをクリックすると、コールアウトがトリガーされます。 - これは地獄のようにうまく動作します。 問題:

let camera = MGLMapCamera(lookingAtCenterCoordinate: annotation.coordinate, fromDistance: 1000, pitch: 0, heading: 0) 
    mapView.setCamera(camera, withDuration: 2, animationTimingFunction: CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)) 

または

:。私はこのようなものを使用するたびに、私はズームアップ、マーカー/注釈や吹き出しでのMapViewを中央、またはセンターでそれらを表示するためにカメラを移動したいのですが
mapView.setCenterCoordinate(annotation.coordinate, zoomLevel: 15, animated: true) 

吹き出しは同じ位置にとどまります。私が達成したいのは、アノテーション/マーカーの上にスティッキーで表示されているということです。

これは、この部分のための私の完全なコード(のviewDidLoadで注釈の建物が含まれていません。

func mapView(mapView: MGLMapView, imageForAnnotation annotation: MGLAnnotation) -> MGLAnnotationImage? { 
    var annotationImage = mapView.dequeueReusableAnnotationImageWithIdentifier("marker_live") 

    if annotationImage == nil { 
     // Leaning Tower of Pisa by Stefan Spieler from the Noun Project 
     var image = UIImage(named: "marker_live")! 
     image = image.imageWithAlignmentRectInsets(UIEdgeInsetsMake(0, 0, image.size.height/2, 0)) 

     annotationImage = MGLAnnotationImage(image: image, reuseIdentifier: "marker_live") 
    } 

    return annotationImage 
} 


func mapView(mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool { 
    print("tap on annotation") 
    mapView.selectAnnotation(annotation, animated: true) 

    return true 
} 

func mapView(mapView: MGLMapView, calloutViewForAnnotation annotation: MGLAnnotation) -> UIView? { 

    return CustomCalloutView(representedObject: annotation) 

} 

func mapView(mapView: MGLMapView, tapOnCalloutForAnnotation annotation: MGLAnnotation) { 
    print("Tapped the callout for: \(annotation.title!)") 
    self.performSegueWithIdentifier("PlaylistFromMap", sender: annotation.title!) 
    mapView.deselectAnnotation(annotation, animated: true) 
} 

私も完了ハンドラを使用して考えたが、それがどのように機能するかを理解していなかった ヘルプをずっと。感謝!

答えて

1

我々がV3.3.0に追加する探しているthis is a feature表示されますが、された後、現在は更新できません吹き出しビューの位置が。

後コールアウトを開くにはまたはsetCoordinate:のアニメーションでは、完了ハンドラを含むメソッドのバリアントを使用してから、selectAnnotation:を使用します。

+0

これまで理解されていましたが、どうすればアノテーションのタッチを検出できますか?これまでのところ、2つのデリゲートがあります。-mapView:didSelectAnnotation: と-mapView:annotationCanShowCallout:私はタッチを検出するために使用しました。最初のものでは、私はカメラの動きをトリガすることができますし、完了後に注釈を選択します(再度)。 2番目に私はコールアウトを表示することができました。最初にアノテーションを実際に選択せずにカメラと選択をトリガーするにはどうすればよいですか? – lightwaver

+0

少なくとも、Mapbox iOS SDKが提供するメソッドではできません。 – friedbunny

+0

私の問題は、カメラをトリガするために 'selectAnnotation'を使用していることです。カメラを個別にトリガする方法やコールアウトが必要です。私が探しているものは何ですか? – lightwaver

関連する問題