gpt4 book ai didi

ios - 无法显示用户当前位置 Mapbox iOS API

转载 作者:可可西里 更新时间:2023-11-01 01:35:43 25 4
gpt4 key购买 nike

我想在用户打开应用后立即显示他们的当前位置。我使用 Mapbox iOS SDK。但它根本不起作用。我不知道出了什么问题。打开后只能看到一张无关的 map 。

import UIKit
import Mapbox
import CoreLocation

class ViewController: UIViewController, MGLMapViewDelegate, CLLocationManagerDelegate
{

@IBOutlet weak var mapView: MGLMapView!

let locationManager = CLLocationManager()

override func viewDidLoad()
{
super.viewDidLoad()
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
}


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

// MARK: Location Delegate Methods

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
let location = locations.last
let mapView = MGLMapView(frame: view.bounds)
mapView.userTrackingMode = .Follow
let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
mapView.setCenterCoordinate(center, zoomLevel: 15, animated: true)
view.addSubview(mapView)
self.locationManager.stopUpdatingLocation()
}

func locationManager(manager: CLLocationManager, didFailWithError error: NSError)
{
print ("Errors:" + error.localizedDescription)
}
}

最佳答案

我认为问题可能出在 iOS 模拟器上。当你在模拟器上运行一个应用程序时,它不会模拟你的位置,直到你告诉它。如果您查看 Xcode,您会在底部看到一个导航按钮。

enter image description here

尝试将位置更改为某个位置,它应该会显示 :)

关于ios - 无法显示用户当前位置 Mapbox iOS API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37757761/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com