【问题标题】:Changing GoogleMaps map type更改 GoogleMaps 地图类型
【发布时间】:2016-12-07 14:16:18
【问题描述】:

我有一个简单的代码,它显示了一个包含几个不同位置的地图,这些位置会根据表中单击的行而变化。地图显示为预期,但是当我尝试将类型更改为卫星时,地图只是淡出,但谷歌徽标仍然存在,我在地图上设置的标记也是如此。我无法弄清楚我在这里缺少什么。这是一些代码。

@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)
}

【问题讨论】:

    标签: ios swift google-maps maps


    【解决方案1】:

    我的问题的答案是,确保在 google.developer 上为您尝试使用它的应用启用 GoogleMap API。感谢大家的贡献:/

    【讨论】:

      猜你喜欢
      • 2021-03-11
      • 1970-01-01
      • 1970-01-01
      • 2011-09-04
      • 1970-01-01
      • 2016-07-17
      • 1970-01-01
      • 2017-11-20
      • 1970-01-01
      相关资源
      最近更新 更多