Swift 视图左上角的 GMSMarker 图标
Swift GMSMarker icon in the top left corner of the view
标题不言自明。我试过按照建议 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)
}
我找到了解决方法,所以我把它放在这里以防其他人遇到这个问题。
我从使用 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)
}
标题不言自明。我试过按照建议 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)
}
我找到了解决方法,所以我把它放在这里以防其他人遇到这个问题。
我从使用 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)
}