8
votes

I'm trying to add a map using GMSMapView but I'm getting errors when I create an outlet for the view.

The following is the code snippet:

import UIKit
import GoogleMaps

class MapViewController: UIViewController {

    @IBOutlet weak var mapVIew: GMSMapView!
    @IBOutlet weak var mapCenterPinImage: UIImageView!
    @IBOutlet weak var pinImageVerticalConstraint: NSLayoutConstraint!
    var searchedTypes = ["bakery", "bar", "cafe", "grocery_or_supermarket", "restaurant"]
    let locationManager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()
        locationManager.delegate = self
        locationManager.requestWhenInUseAuthorization()
    }
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "Types Segue" {
            let navigationController = segue.destinationViewController as! UINavigationController
            let controller = navigationController.topViewController as! TypesTableViewController
            controller.selectedTypes = searchedTypes
            controller.delegate = self
        }
    }
}

I'm getting the following errors at line

@IBOutlet weak var mapVIew: GMSMapView!:
  1. weak may only be applied to class and class-bound protocol types not <>
  2. use of undeclared type "GMSMapView"

Please can someone help me out

4
Have you assign GMSMapView class to that view from story board? - Jigar Tarsariya
@JigarTarsariya Yes i have - PersianBlue
Remove weak and make IBOutlet of that view - Jigar Tarsariya
Did you try add import GoogleMaps on the top of file? - t4nhpt
@PersianBlue so basically the original question is now answered. Neither the title of the question, nor it's contents (excepting the code) correspond to your current issue. Please update. - Cristik

4 Answers

9
votes

The marked answer is not the correct answer to this problem. In case anyone else hits this, the problem is the framework needed is not imported. In this case GoogleMaps. The fix for this is, at the top of file add

import GoogleMaps

Another example is if you get the error after adding an MkMapView.

@IBOutlet weak var mapView: MKMapView

For this you'll have to import MapKit

import MapKit
3
votes

Note : Updating this answer to avoid misunderstanding as I have answered wrong earlier. Thanks @Inn0vative1 for pointing out error

For this you'll have to import MapKit

import MapKit

Your viewController did not confirm the protocol, Please conform the CLLocationManagerDelegate protocol

class MapViewController: UIViewController,CLLocationManagerDelegate {
}
0
votes

One will also get this issue, if the library containing the control is not imported.

eg., if we are trying to create an IBOutlet to a PDFView control and Quartz library is not imported, this error pops in.

0
votes

Recently I also met this problem. I fixed this by uncheck the target membership --xxxTests. One of my file checked the xxxTests target.