gpt4 book ai didi

ios - myLocationButton 未显示在 Google map 上

转载 作者:行者123 更新时间:2023-11-29 02:06:13 26 4
gpt4 key购买 nike

我已按照教程中的步骤操作如何通过 Google Maps SDK 获取用户的位置。我使用了Google提供的教程,也由Ray Wenderlich提供但这没有用。位置按钮甚至不显示。

任何帮助都会很棒,谢谢。这是我的代码:

    class NearestDealerViewController: UIViewController, CLLocationManagerDelegate {

@IBOutlet weak var mainMenuLabel: UILabel!
@IBOutlet weak var nearestDealer: UILabel!
@IBOutlet weak var mapView: GMSMapView!
let locationManager = CLLocationManager()

let transitionDelegate = TransitionDelegate()
var delegate: NearestDealerViewControllerDelegate?

override func viewDidLoad() {
super.viewDidLoad()

locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
println(mapView.myLocationEnabled)
}

func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
if status == .AuthorizedWhenInUse {
locationManager.startUpdatingLocation()
mapView.myLocationEnabled = true
mapView.settings.myLocationButton = true
}
println(mapView.myLocationEnabled)

}

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
if let location = locations.first as? CLLocation {
mapView.camera = GMSCameraPosition(target: location.coordinate, zoom: 15, bearing: 0, viewingAngle: 0)
locationManager.stopUpdatingLocation()
}
}

@IBAction func backTapped(sender: AnyObject) {
delegate?.dismissNearestDealerViewController()
}
}

最佳答案

您应该在 viewDidLoad() 的下一行代码中放入:

mapView.isMyLocationEnabled = true

关于ios - myLocationButton 未显示在 Google map 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29765865/

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