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:
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.
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:
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.
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:
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.
I fixed it by go to my view (view display map), then change class my view to GMSMapView.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With