7

I just upgraded to Xcode 7.1. When I try to set the mapType of a GMSMapView I get the 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
        }
}
wxcoder
  • 665
  • 1
  • 13
  • 32

6 Answers6

12

I'm not sure why but putting "GoogleMaps." in front of all the kGMSTypes (i.e. GoogleMaps.kGMSTypeNormal) fixed the problem.

wxcoder
  • 665
  • 1
  • 13
  • 32
  • Solved my problem. – tmagalhaes May 05 '16 at 13:28
  • I suspect this happens because the enums are duplicated in some frameworks and when using GoogleMaps.kGMS... you are referencing the constant using its absolute and unmistakable identifier. Any way - this works. – gcasar Aug 03 '16 at 10:14
2
mapView.mapType = GMSMapViewType(rawValue: 1)!
  • kGMSTypeNormal = 1
  • kGMSTypeSatellite = 2
  • kGMSTypeTerrain = 3
  • kGMSTypeHybrid = 4
  • kGMSTypeNone = 5
Channel
  • 2,183
  • 21
  • 16
2

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

In Swift 3 use as bellow:

.normal .hybrid .satellite .terrain

Shinichi
  • 475
  • 4
  • 7
  • 25
0

If you open GMSMapViewType, you will see it defined as enum. In your switch statement, you're comparing it with strings which is wrong. You should better compare them with integers.

kGMSTypeNormal = 1
kGMSTypeSatellite = 2
kGMSTypeTerrain = 3
kGMSTypeHybrid = 4
kGMSTypeNone = 5
Bhavuk Jain
  • 2,167
  • 1
  • 15
  • 23
  • Doing `let myMapType = NSUserDefaults.standardUserDefaults().integerForKey(SettingsTableViewController.History.MapType) if myMapType == 1 { mapView.mapType = kGMSTypeNormal }` still gives me the same error. In fact, i'm unable to define the mapType anywhere in the class as it just comes up as being ambiguous. – wxcoder Oct 26 '15 at 06:03
  • let myMapType = NSUserDefaults.standardUserDefaults().integerForKey(SettingsTableViewController.‌​History.MapType). What value do you get on myMapType? – Bhavuk Jain Oct 26 '15 at 06:15
  • It is an Int. Xcode complains about this at compile time. – wxcoder Oct 26 '15 at 06:23
  • I don't see any problem with this: if myMapType == 1 { mapView.mapType = kGMSTypeNormal }. So you must check this let myMapType = NSUserDefaults.standardUserDefaults().integerForKey(SettingsTableViewController.‌​History.MapType) – Bhavuk Jain Oct 26 '15 at 06:31
0

You need to use like this

mapView.mapType = GoogleMaps.kGMSTypeSatellite

tonymontana
  • 5,728
  • 4
  • 34
  • 53