8

I currently have a UIView in my View Controller which I have changed to a GMSMapView in the Interface Builder, but nothing shows up, as shown in the picture below:

enter image description here

Here is the code that I am using

    let lat = 47.07903
    let long = -122.961283

    let camera = GMSCameraPosition.cameraWithLatitude(lat, longitude: long, zoom: 10)
    let map = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
    map.myLocationEnabled = true
    map.delegate = self
    self.mapView.addSubview(map)

    let marker = GMSMarker()
    marker.position = CLLocationCoordinate2DMake(lat, long)
    marker.map = self.mapView

I have declared mapView as such using drag and drop:

@IBOutlet var mapView: GMSMapView!

Any help here would be much appreciated. I have tried a lot of different things! Thanks!

Sampath Duddu
  • 237
  • 5
  • 13
  • Ensure the bundle identifier set in https://console.developers.google.com matches your current app's bundle identifier – kye Apr 01 '16 at 22:51
  • That actually helped, but now I get another issue where the map starts out somewhere in London, even though my marker is being placed correctly – Sampath Duddu Apr 01 '16 at 23:45
  • Please refer to the answer below. – kye Apr 01 '16 at 23:55
  • Try to set frame to the map view in `let map = GMSMapView.mapWithFrame(CGRectZero, camera: camera)` – fnc12 Jun 28 '17 at 07:15
  • check here https://stackoverflow.com/questions/15417811/cannot-put-a-google-maps-gmsmapview-in-a-subview-of-main-main-view/48517389#48517389 – Heshan Sandeepa Jan 30 '18 at 09:02

5 Answers5

11

This worked for me. https://stackoverflow.com/a/47308301/7560912 You probably have not enabled the google maps API. Go to your app-project's dashboard on https://console.developers.google.com and click the "ENABLE APIS AND SERVICES". There, under the MAPS section select "the Google maps sdk for ios" and enable it.

HighAbove
  • 311
  • 3
  • 9
  • @ HighAbove . In my case. I created + used valid key, but it has to be enable. By default it is Disable. – Ravi Nov 01 '18 at 18:16
7

As I was facing same problem and i have found some of my mistakes because of that i am facing same issue.

1) Please create your ios app in google map account.

2) enable maps for you app from google map developer site.

3) use ios google services key in your app.

GMSPlacesClient.provideAPIKey("API-KEY")
GMSServices.provideAPIKey("API-KEY")

4) must be sure that bundle identifier you are providing is should correct spelled.

Above mistakes is giving me issue please check it.

Hardik Vyas
  • 1,263
  • 17
  • 35
3

Make sure you've got a valid API key from Google Dev Console, and it is correctly added to your app.

In your AppDelegate.m on application:didFinishLaunchingWithOptions: you should have this:

[GMSServices provideAPIKey:@"YOUR_API_KEY"];

For more details, go through steps 4 and 5 HERE

Zika M
  • 289
  • 1
  • 5
3

"ENABLE APIS AND SERVICES". enter image description here

work for me, you can try it.

Ha cong Thuan
  • 653
  • 1
  • 10
  • 14
0

To update your mapview after placing a marker you can set the maps camera to GMSCameraPostion. You can read more about markers here-> https://developers.google.com/maps/documentation/ios-sdk/marker#change_the_marker_opacity

 let marker = GMSMarker()
 marker.position = CLLocationCoordinate2DMake(22.3039, 70.8022)
 marker.map = self.mapView
 viewMap.camera = GMSCameraPosition.camera(withTarget: marker.position, zoom: 13)
Pranav Kasetti
  • 4,773
  • 2
  • 16
  • 38
kye
  • 1,929
  • 2
  • 21
  • 36