【问题标题】:Swift GMSMarker icon in the top left corner of the view视图左上角的 Swift GMSMarker 图标
【发布时间】:2019-06-29 16:54:42
【问题描述】:

标题是不言自明的。我已经尝试按照here 的建议在viewDidLayoutSubviews() 中调用它,但这并没有给我带来快乐。

这是我的代码:

override func viewDidLoad() {
    super.viewDidLoad()

    locationManager.requestWhenInUseAuthorization()

    mapView.mapType = .normal
    mapView.settings.zoomGestures   = true
    mapView.settings.tiltGestures   = true
    mapView.settings.rotateGestures = true
    mapView?.isMyLocationEnabled = true
    locationManager.startUpdatingLocation()
    locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation
    locationManager.delegate = self


    // Do any additional setup after loading the view, typically from a nib.
}

override func viewDidAppear(_ animated: Bool) {
    if(locationManager.location != nil){
        centerMapOnLocation(location: locationManager.location!)
    }
}

func centerMapOnLocation(location: CLLocation)
{
    let camera = GMSCameraPosition.camera(withLatitude: locationManager.location!.coordinate.latitude, longitude: locationManager.location!.coordinate.longitude, zoom: zoom)
        mapView?.animate(to: camera)
}

【问题讨论】:

    标签: swift google-maps cllocationmanager


    【解决方案1】:

    我已经找到了解决办法,所以我把它放在这里以防其他人遇到这个问题。

    我从使用mapView?.animate 更改为GMSCameraPosition.camera,它似乎工作正常。

    func centerMapOnLocation(location: CLLocation)
    {
        let target = CLLocationCoordinate2D(latitude: locationManager.location!.coordinate.latitude, longitude: locationManager.location!.coordinate.longitude)
        mapView.camera = GMSCameraPosition.camera(withTarget: target, zoom: zoom)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-10
      • 1970-01-01
      • 2016-08-28
      • 2019-01-13
      • 1970-01-01
      • 2017-01-18
      • 2018-12-18
      相关资源
      最近更新 更多