【问题标题】:I am not getting camera position at my location using Google Map in iOS我没有在 iOS 中使用 Google 地图获取我所在位置的相机位置
【发布时间】:2018-06-02 19:36:08
【问题描述】:

我在 iOS 上使用 Google 地图,我在我的位置获取标记,但没有将相机位置获取到我的位置。我看过很多教程,但没有得到任何解决方案。

我的代码是:

mapView = GMSMapView()
        locationManager = CLLocationManager()
        // locationManager.delegate = self
        locationManager.requestAlwaysAuthorization()
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.startUpdatingLocation()
        placesClient = GMSPlacesClient.shared()

        // GOOGLE MAPS SDK: COMPASS
        mapView.settings.compassButton = true

        // GOOGLE MAPS SDK: USER'S LOCATION
        mapView.isMyLocationEnabled = true
        mapView.settings.myLocationButton = true
        mapView.animate(toBearing: 0)


 func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
    {
        if  let location = locations.last
        {
            print("location\(String(describing: location))")

         //   mapView.clear()
            let marker = GMSMarker(position: CLLocationCoordinate2D(latitude:location.coordinate.latitude, longitude: location.coordinate.longitude))
            marker.map = mapview
            mapView.camera = GMSCameraPosition.camera(withLatitude: location.coordinate.latitude,
                                                      longitude: location.coordinate.longitude,
                                                      zoom: 50)

        }
        locationManager.stopUpdatingLocation()
    }

【问题讨论】:

标签: ios swift google-maps


【解决方案1】:

请务必检查 GMSMapView.padding。它可能与 GMSMapView 的矩形不同,然后相机将指向另一个位置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-29
    • 2017-08-14
    • 2016-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-08
    相关资源
    最近更新 更多