wxcoder
wxcoder

Reputation: 655

Google Maps ambiguous use of a GMSMapViewType

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

Upvotes: 7

Views: 2482

Answers (6)

Casey Shimata
Casey Shimata

Reputation: 19

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


    }

Upvotes: 2

Shinichi
Shinichi

Reputation: 505

In Swift 3 use as bellow:

.normal .hybrid .satellite .terrain

Upvotes: 1

Channel
Channel

Reputation: 2273

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

Upvotes: 2

Ajay Parmar
Ajay Parmar

Reputation: 11

You need to use like this

mapView.mapType = GoogleMaps.kGMSTypeSatellite

Upvotes: 0

wxcoder
wxcoder

Reputation: 655

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

Upvotes: 12

Bhavuk Jain
Bhavuk Jain

Reputation: 2187

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

Upvotes: 0

Related Questions