2017-11-22 12 views
0

Mapbox를 사용하여 내 앱을 만듭니다. 버튼을 클릭하면 현재 위치를 표시하고 현재 위치와 마찬가지로 마커를 추가하고 싶습니다. 그런 다음이 마커를 탭하여 표시된 지점의 주소와 같은 현재 위치 정보를 표시하는 것이 좋습니다.Mapbox를 사용하여 사용자 정의 위치 주석 만들기

는 지금 내가 가지고있는 모든

https://imgur.com/a/RSx0G

내가 미리 모든 의견을 보내 주셔서 감사합니다 내가 엑스 코드 9.1 스위프트 (4)를 사용하고 있습니다 싶습니다 ...입니다. 당신은 MGLUserLocationAnnotationView의 서브 클래스를 생성 할 수 있습니다

import Foundation 
import UIKit 
import CoreLocation 
import Mapbox 
import MapKit 
import MapboxGeocoder 

class SecondViewController: UIViewController, CLLocationManagerDelegate, MGLMapViewDelegate, UITextFieldDelegate { 

let geocoder = Geocoder.shared 

let dismissesAutomatically: Bool = false 
let isAnchoredToAnnotation: Bool = true 

weak var delegate: MGLCalloutViewDelegate? 

let tipHeight: CGFloat = 10.0 
let tipWidth: CGFloat = 20.0 

@IBOutlet var mapView: MGLMapView! 
let manager = CLLocationManager() 

override func viewDidLoad() { 
super.viewDidLoad() 
manager.delegate = self 
manager.desiredAccuracy = kCLLocationAccuracyBest 
manager.requestWhenInUseAuthorization() 

} 

override func didReceiveMemoryWarning() { 
super.didReceiveMemoryWarning() 

} 

@IBAction func markStuff(_ sender: Any) { 
} 
@IBAction func refLocation(_ sender: Any) { 
manager.startUpdatingLocation() 

} 
func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool { 
return true 
} 


func mapView(_ mapView: MGLMapView, viewFor annotation: MGLAnnotation) -> MGLAnnotationView? { 
return nil 
} 

    func mapView(_ mapView: MGLMapView, tapOnCalloutFor annotation: MGLAnnotation) 
{ 

print("tap on callout") 

} 

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { 
let location = locations[0] 

let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude) 

mapView.setCenter(center, zoomLevel: 10, animated: true) 

let annotation = MGLPointAnnotation() 

annotation.coordinate = location.coordinate 

mapView.selectAnnotation(annotation, animated: true) 

annotation.title = "Testing" 
annotation.subtitle = "\(annotation.coordinate.latitude), \(annotation.coordinate.longitude)" 

self.mapView.addAnnotation(annotation) 

manager.stopUpdatingLocation() 

답변

2

현재 신속한 파일의 모습은 ... 다음, 그 MGLUserLocation 주석에 대한보기로 사용할 수 있습니다. 완벽하게 구현, 공식 문서에서 see this example를 들어

func mapView(_ mapView: MGLMapView, viewFor annotation: MGLAnnotation) -> MGLAnnotationView? {This custom view is created below. 
    if annotation is MGLUserLocation && mapView.userLocation != nil { 
     return YourLocationAnnotationView() 
    } 
    return nil 
    } 
} 

: 사용자 정의 서브 클래스가 YourLocationAnnotationView()를 호출 된 경우

예를 들어, 당신이 뭔가를 할 수 있습니다.