在视图的左上角斯威夫特GMSMarker图标

问题描述 投票:0回答:1

标题是非常自我解释。我试过称其为viewDidLayoutSubviews()的建议here,但它给了我不快​​乐。

这里是我的代码:

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个回答
0
投票

我已经想通了修复,所以我把它在这里情况下别人有这个问题。

我使用mapView?.animateGMSCameraPosition.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)
}
© www.soinside.com 2019 - 2024. All rights reserved.