0
我有一個簡單的代碼,它顯示了幾個不同位置的地圖,這些地圖會根據表中點擊的行進行更改。地圖顯示爲預期的,但是當我嘗試將類型更改爲Satellite時,地圖只是淡出,但Google徽標仍然存在,我在地圖上設置的標記也一樣。我無法弄清楚我在這裏錯過了什麼。這裏有一些代碼。更改Google地圖的地圖類型
@IBOutlet var myMapView: UIView!
var mapView: GMSMapView?
var currentLocation: CLLocationCoordinate2D?
let locationManager = CLLocationManager()
var marker = GMSMarker()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
kreirajMapu() - creates the map
}
func kreirajMapu() {
currentLocation = magacin[red].artikal[redZaMapu].lokacija
let camera = GMSCameraPosition.camera(withLatitude: (currentLocation?.latitude)!, longitude: (currentLocation?.longitude)!, zoom: 15)
mapView = GMSMapView.map(withFrame: myMapView.bounds, camera: camera)
mapView?.autoresizingMask = [.flexibleWidth, .flexibleHeight]
mapView?.isMyLocationEnabled = true
mapView?.settings.compassButton = true
mapView?.settings.myLocationButton = true
mapView?.settings.setAllGesturesEnabled(true)
myMapView.addSubview(mapView!)
}
func moveCamera() {
CATransaction.begin()
CATransaction.setValue(2, forKey: kCATransactionAnimationDuration)
mapView?.animate(to: GMSCameraPosition.camera(withTarget: magacin[red].artikal[redZaMapu].lokacija, zoom: magacin[red].artikal[redZaMapu].zoom))
mapView?.animate(toViewingAngle: 45)
CATransaction.commit()
marker = GMSMarker(position: magacin[red].artikal[redZaMapu].lokacija)
marker.title = magacin[red].artikal[redZaMapu].naziv
marker.appearAnimation = kGMSMarkerAnimationPop
marker.snippet = "This is where \(magacin[red].artikal[redZaMapu].naziv)'s live"
marker.map = mapView
}
@IBAction func mapType(_ sender: AnyObject) {
let actionSheet = UIAlertController(title: "Map Types", message: "Select map type:", preferredStyle: .actionSheet)
actionSheet.addAction(UIAlertAction(title: "Normal", style: .default, handler: {_ in
self.mapView?.mapType = kGMSTypeNormal
}))
actionSheet.addAction(UIAlertAction(title: "Hybrid", style: .default, handler: {_ in
self.mapView?.mapType = kGMSTypeHybrid
}))
actionSheet.addAction(UIAlertAction(title: "Satellite", style: .default, handler: {_ in
self.mapView?.mapType = kGMSTypeSatellite
}))
actionSheet.addAction(UIAlertAction(title: "Terrain", style: .default, handler: {_ in
self.mapView?.mapType = kGMSTypeTerrain
}))
actionSheet.addAction(UIAlertAction(title: "Cancel", style: .cancel))
present(actionSheet, animated: true, completion: nil)
}