0
私は、テーブル内のクリックされた行に応じて変化するわずかな位置のマップを提示する簡単なコードを持っています。地図が見えているようですが、タイプを変えようとすると、地図は消えてしまいますが、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)
}