मैं उपयोगकर्ता के स्थान के अक्षांश और देशांतर को खोजने का प्रयास कर रहा हूं ताकि मैं उपयोगकर्ता को मानचित्र को viewdidload में केंद्रित कर सकूं।आईओएस एसडीके के लिए मैपबॉक्स में उपयोगकर्ता स्थान का उपयोग करके मुझे सही स्थान डेटा कैसे प्राप्त करना चाहिए? (स्विफ्ट)
मैंने लागू किया है जो सही कोड प्रतीत होता है लेकिन उपयोगकर्ता डेटा (अक्षांश) और उपयोगकर्ता लॉन (रेखांश) के मान बंद हैं।
एनबी। किसी और के रूप में मुझे एक ही समस्या थी, लेकिन उसके जवाब का समाधान कभी नहीं किया गया था: Mapbox iOS8 Swift mapView.showUsersLocation
import Mapbox
class ViewController: UIViewController, MGLMapViewDelegate, CLLocationManagerDelegate {
// let locationManager = CLLocationManager()
@IBOutlet weak var mapView: MGLMapView!
override func viewDidLoad() {
super.viewDidLoad()
// Initalise map's center coordinate as vancouver
mapView.setCenterCoordinate(CLLocationCoordinate2D(latitude: 49.283382,
longitude: -123.117394),
zoomLevel: 15, animated: false)
view.addSubview(mapView)
// Set the delegate property of our map view to self after instantiating it.
mapView.delegate = self
// User location
mapView.showsUserLocation = true
let userLoc = mapView.userLocation!
userLoc.title = "Hello"
userLoc.subtitle = "I am here!"
let userLat = userLoc.coordinate.latitude
let userLon = userLoc.coordinate.longitude
print(userLat, userLon)
/*
self.locationManager.requestAlwaysAuthorization()
if CLLocationManager.locationServicesEnabled() {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager.startUpdatingLocation()
}*/
}
func mapView(mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool {
return true
}
}
परिणामस्वरूप प्रिंट:
3.40282346638529e+38 3.40282346638529e+38
अजीब बात यह है कि एनोटेशन ठीक काम करता है, और है, जब मैं अपने स्थान पर क्लिक करें मुझे शीर्षक और उपशीर्षक मिलता है।