Google Maps iOS SDK Tutorial: Getting Started

@ron.kliffer great tut. if you make a marker draggable, is there a way to turn off the ‘padding’ type movement that occurs to give the perception of ‘lifting’ the marker? the map moves up, and the marker along with it (and then back down when you end the drag). I assume its in the GMSMapView delegate functions. I’ve been able to contain the map moving, but I can’t seem to stop the marker from going UP on drag. any insight would be really helpful.

@ron.kliffer great tutorial. I just got a small problem here for the location pins.
The Google Maps API key (no restriction) that I applied myself seems doesn’t work well, instead the Google Places API key from my teacher does the work.
Did I miss something?

I was wondering if anyone could help me figure out how to make a randomly chosen marker’s infoView pop up on a button press. Essentially a way to have it pseudo randomly select a place. I am looking in the documentation on selectedMarker, but can’t figure out a way to randomly select one so that it brings up the info window? Hopefully, that makes some sense. Thanks! @ron.kliffer @shogunkaramazov

HI Ron,
Great job!
Do you still have this tutorial in Swift 3? Don’t really wanna upgrade at the moment.
Thanks!

@ron.kliffer Can you please help with this when you get a chance? Thank you - much appreciated! :]

Hi,
I tried to implement code, but not able update current location.I tried to update current location but still does not change default setting. Geolocation coordinate takes ‘San Francisco’ as default location.I have hardcoded latitude and longitude,still does not work properly. Any help will be appreciated.

Thanks,
Prannoy Singh

Hi, unfortunately I do not have the code in Swift 3, but the code shouldn’t be that different between Swift 3 and 4

Hi,
You could try saving all the markers in an array, pulling one randomly from the array, and setting it as the map’s selected marker. Let me know if that works

It’s hard for me to say exactly, can you compare with you teacher and see what you did different?

Can you please add the snippet where you set the location? thanks

Given an array of addresses of places, how can I show them all on the map? for example : 77 Bayard Street, 65 Bayard Street etc


You’d have to geocode each address into a coordinate, then create a marker for each coordinate and place it on the map.
Check out Overview  |  Geocoding API  |  Google Developers for more details on address geocoding

Hello friends. If like me you could not get the place markers to show up and also like me only added the Places SDK for iOS API, I was able to fix the issue by adding the Places API. As stated above, there can be no API or Application restrictions on the app.

At the Getting The Location section I’m getting an error:
"Ambiguous reference to member ‘locationManager(_.didChangeAuthorization:)’

on these two lines;

locationManager.startUpdatingLocation()
locationManager.stopUpdatingLocation()

I’m on Xcode 9.3.1, did something change on this version to cause this error? My MapViewController.swift is below.

import UIKit
import GoogleMaps

private let locationManger = CLLocationManager()

class MapViewController: UIViewController {

@IBOutlet private weak var mapCenterPinImage: UIImageView!
@IBOutlet private weak var pinImageVerticalConstraint: NSLayoutConstraint!
var searchedTypes = [“bakery”, “bar”, “cafe”, “grocery_or_supermarket”, “restaurant”]

override func viewDidLoad() {
super.viewDidLoad()
locationManger.delegate = self
locationManger.requestWhenInUseAuthorization()
}

@IBOutlet weak var mapView: GMSMapView!
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
guard let navigationController = segue.destination as? UINavigationController,
  let controller = navigationController.topViewController as? TypesTableViewController else {
    return
}
controller.selectedTypes = searchedTypes
controller.delegate = self

}
}

// MARK: - TypesTableViewControllerDelegate
extension MapViewController: TypesTableViewControllerDelegate {
func typesController(_ controller: TypesTableViewController, didSelectTypes types: [String]) {
searchedTypes = controller.selectedTypes.sorted()
dismiss(animated: true)
}
}

// MARK: - CLLocationManagerDelegate
//1
extension MapViewController: CLLocationManagerDelegate {
// 2
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
// 3
guard status == .authorizedWhenInUse else {
return
}
// 4
locationManager.startUpdatingLocation()

//5
mapView.isMyLocationEnabled = true
mapView.settings.myLocationButton = true

}

// 6
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let location = locations.first else {
return
}

// 7
mapView.camera = GMSCameraPosition(target: location.coordinate, zoom: 15, bearing: 0, viewingAngle: 0)

// 8
locationManager.stopUpdatingLocation()

}
}

You declared you property as locationManger instead of locationManager (missing an a):
private let locationManger = CLLocationManager()

1 Like

Son of nut cracker
 it’s always something small!! Thank you good sir!!

I just now got a chance to fix that typo. Now it shows that Ambiguous error on the original 2 lines plus both of the locationManager lines inside of the viewDidLoad function. Swift did throw an error about locationManager.delegate = self needing to be self as? CLLocationManagerDelegate. Could that have something to do with the Ambiguous errors?

override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self as? CLLocationManagerDelegate
locationManager.requestWhenInUseAuthorization()
}

@ron.kliffer Do you have any feedback regarding this? Thank you - much appreciated! :]

Just for giggles I changed the declared property from locationManager to locmanager and updated the 4 lines where the error was showing. The errors went away and the app loads. Is this because there are functions called locationManager?

After digging through everything and downloading the completed project I realized my code wasn’t organized correctly. Some of the IBOutlet, variables, and functions weren’t inside of the MapViewController class that needed to be. Now that it’s all fixed everything works great. I had to go back and enable the Places API for my api key instead of the Places IOS.

Thanks for the great tutorial. I managed to follow all the way through but no matter what I did I can’t seem to get the images to display the location pins from the fetchNearbyPlaces() function
 I tried downloading the completed projects and key in my API_key as well.