Sampath Duddu
Sampath Duddu

Reputation: 277

GMSMapView not showing anything

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!

Upvotes: 10

Views: 11750

Answers (6)

Tushar E
Tushar E

Reputation: 1

hey i faced the same issue when only the marker was shown and the google maps wasn't rendering. The solution for me was to make sure i was entering the right api key in the app delegate and the info.plist

Upvotes: 0

kye
kye

Reputation: 2246

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)

Upvotes: 0

Ha cong Thuan
Ha cong Thuan

Reputation: 683

"ENABLE APIS AND SERVICES". enter image description here

work for me, you can try it.

Upvotes: 4

Hardik Vyas
Hardik Vyas

Reputation: 2253

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.

Upvotes: 8

HighAbove
HighAbove

Reputation: 339

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.

Upvotes: 13

Zika M
Zika M

Reputation: 309

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

Upvotes: 3

Related Questions