Google Maps ambiguous use of a GMSMapViewType
Asked Answered
D

6

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
        }
}
Demonology answered 26/10, 2015 at 5:12 Comment(0)
D
12

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

Demonology answered 27/10, 2015 at 4:16 Comment(2)
Solved my problem.Seasick
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.Ihab
B
2
mapView.mapType = GMSMapViewType(rawValue: 1)!
  • kGMSTypeNormal = 1
  • kGMSTypeSatellite = 2
  • kGMSTypeTerrain = 3
  • kGMSTypeHybrid = 4
  • kGMSTypeNone = 5
Brenza answered 3/3, 2017 at 20:55 Comment(0)
S
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


    }
Syllogize answered 14/6, 2017 at 22:6 Comment(0)
T
1

In Swift 3 use as bellow:

.normal .hybrid .satellite .terrain

Tenant answered 14/3, 2017 at 1:53 Comment(0)
S
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
Solitary answered 26/10, 2015 at 5:53 Comment(4)
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.Demonology
let myMapType = NSUserDefaults.standardUserDefaults().integerForKey(SettingsTableViewController.‌​History.MapType). What value do you get on myMapType?Solitary
It is an Int. Xcode complains about this at compile time.Demonology
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)Solitary
V
0

You need to use like this

mapView.mapType = GoogleMaps.kGMSTypeSatellite

Vino answered 9/6, 2016 at 9:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.