Google Maps ambiguously uses GMSMapViewType

I just upgraded to Xcode 7.1. When I try to set mapType for the GMSMapView, I get an error. Ambiguous use of "kGMSTypeNormal", ambiguous use of "kGMSTypeTerrain" and ambiguous use of "kGMSTypeHybrid".

@IBOutlet weak var mapView: GMSMapView! func myfunc() { if let myMapType = NSUserDefaults.standardUserDefaults().stringForKey(SettingsTableViewController.History.MapType) { switch myMapType { case "kGMSTypeNormal": mapView.mapType = kGMSTypeNormal case "kGMSTypeTerrain": mapView.mapType = kGMSTypeTerrain case "kGMSTypeHybrid": mapView.mapType = kGMSTypeHybrid default: break mapView.mapType = kGMSTypeNormal } } else { mapView.mapType = kGMSTypeNormal } } 
+7
ios swift swift2 google-maps-sdk-ios gmsmapview
source share
6 answers

I'm not sure why, but put "GoogleMaps". before all kGMSTypes (i.e. GoogleMaps.kGMSTypeNormal) the problem is fixed.

+12
source share
 mapView.mapType = GMSMapViewType(rawValue: 1)! 
  • kGMSTypeNormal = 1
  • kGMSTypeSatellite = 2
  • kGMSTypeTerrain = 3
  • kGMSTypeHybrid = 4
  • kGMSTypeNone = 5
+2
source share

here is the updated version

 import UIKit import GoogleMaps class ViewController: UIViewController, GMSMapViewDelegate { var mapView: GMSMapView! override func viewDidLoad() { super.viewDidLoad() mapView = GMSMapView(frame: self.view.bounds) mapView.animate(toViewingAngle: 45) mapView.mapType = GMSMapViewType.satellite self.view = mapView } 
+1
source share

If you open GMSMapViewType, you will see that it is defined as an enumeration. In your switch statement, you are comparing it with strings, which is wrong. You better compare them with integers.

 kGMSTypeNormal = 1 kGMSTypeSatellite = 2 kGMSTypeTerrain = 3 kGMSTypeHybrid = 4 kGMSTypeNone = 5 
0
source share

You need to use like this

mapView.mapType = GoogleMaps.kGMSTypeSatellite

0
source share

In Swift 3 use below:

.normal .hybrid .satellite .terrain

0
source share

All Articles