Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show GoogleMaps on View in Swift?

My code:

var camera = GMSCameraPosition.cameraWithLatitude(currentLocation.latitude, longitude: currentLocation.longitude, zoom: 12) 
//latitude, longitude like :31.230416 and 121.473701.
let map = GMSMapView(frame: CGRectZero)
map.delegate = self
map.camera = camera
self.view = map

It work fine! like this:

enter image description here

But when I create new View: @IBOutlet weak var mapView: UIView!

Then change this line: self.view = map to self.mapView = map

It not work for me, I get a blank view.

like image 433
rome 웃 Avatar asked Sep 07 '15 05:09

rome 웃


People also ask

What is gmsmapview in Swift?

The GMSMapView is part of the Google Maps framework, and actually it’s a UIView subclass. There’s one more modification needed to be done in that view, but this time we must go to the ViewController.swift file. At the top of the class you’ll find the following IBOutlet property declaration:

How to get Google Maps SDK for iOS?

Using your Google account, sign in to the Developers Console and then click to the API Project option given at the following screen: Next, click to expand the APIs & auth menu, and then select the APIs option. By doing so, you’ll find all the available APIs provided by Google, but the one we’re interested in is the Google Maps SDK for iOS.

How do I set the default travel mode in Swift?

In the ViewController.swift file, go to the top of the file, before the class opening, and add the next lines: Inside the class now, let’s declare the default travel mode:

How do you spot to the map in an app?

The first parameter is the address we want to spot to the map. The second parameter is a completion handler that will be called once we have received and processed the response data. The app will display results to the map only after this completion handler has been called by this method.


1 Answers

I fixed it by go to my view (view display map), then change class my view to GMSMapView. enter image description here

like image 139
rome 웃 Avatar answered Oct 23 '22 06:10

rome 웃