myLocationButton 未在 Google 地图上显示

Posted

技术标签:

【中文标题】myLocationButton 未在 Google 地图上显示【英文标题】:myLocationButton doesn't show on Google Maps 【发布时间】:2015-04-21 07:40:04 【问题描述】:

我已按照如何通过 Google Maps SDK 获取用户位置的教程中的步骤进行操作。我也使用了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()
    

【问题讨论】:

我认为您的地图在位置更新时未分配,因此在调用 didChangeAuthorizationStatus 时 nslog 地图视图 @chiragshah 我的 mapView 已连接到我的故事板。而且我还听取了您的建议,对我的 mapView 进行 nslog,它不是零。 你是在模拟器中运行这个项目然后你尝试改变位置。 在模拟器上你必须通过调试来改变你的位置 -> 位置它启用你的位置按钮 应该没问题,反正苹果模拟器在我的位置和它的按钮上存在已知问题。仍有疑问时,请进行测试。只需将其侧面加载到测试设备上并检查即可。 【参考方案1】:

你应该在 viewDidLoad() 下一行代码:

mapView.isMyLocationEnabled = true

【讨论】:

以上是关于myLocationButton 未在 Google 地图上显示的主要内容,如果未能解决你的问题,请参考以下文章

Google GeoChart(Lavacharts 库)-> AddRow / AddRows 未在地图上呈现任何结果,尽管创建了值数组

如何为 google_maps_flutter 设置缩放级别

如何在谷歌地图上快速更改我的位置按钮的位置

text 为Raspberry Pi添加SSMTP支持。如果使用谷歌Gmail,您需要访问此页面以允许更少的安全应用程序:https://myaccount.googl

JSON锛?JavaScript Object Notation

仅显示一个位置权限警报