我在iOS上使用谷歌地图,我在我的位置得到了标记但没有将相机位置放到我的位置。我看过很多教程,但没有得到任何解决方案。
我的代码是:
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()
}
答案 0 :(得分:0)
请务必检查GMSMapView.padding。它可能与您的GMSMapView的矩形不同,然后相机将指向另一个位置。