@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 GoogleMapsprivate 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()
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.