Google Maps Integration iOS Swift. Part 3
2 min readJul 14, 2021
Description: — GoogleMaps with custom theme and Clustering. iOS Swift
So next step is to show our current location on the GoogleMap
- Lets confirm our MapViewController to LocationServiceDelegate and then set our controller as delegate for locationService somewhere in viewDidLoad.
extension MapViewController: LocationServiceDelegate {func updateLocation(_ location: CLLocationCoordinate2D?) {}func authorizattionStatusDidChanged(isAccessGranted: Bool) {// implement some reaction on chnging authorization status}}/// MapViewControlleroverride func viewDidLoad() {
super.viewDidLoad()layoutMapView()
locationService.setDelegate(self)
locationService.startLocationService()}
2. Now i need to configure mapView to allow showing of my current location, i’ll create func which call configMapView() and call this method inide viewDidLoad:
override func viewDidLoad() { super.viewDidLoad() layoutMapView() locationService.startLocationService() configMapView()}private func configMapView() { mapView?.isMyLocationEnabled = true}
3. Now i need some method to update current location if locationService will call updateLocation, and call this method inside updateLocation(_ location: CLLocationCoordinate2D?):
func cameraMoveToLocation(toLocation: CLLocationCoordinate2D?) { if toLocation != nil { let camera = GMSCameraPosition.camera(withTarget: toLocation!, zoom: 15) mapView?.animate(to: camera)}}/////
extension MapViewController: LocationServiceDelegate {func updateLocation(_ location: CLLocationCoordinate2D?) {
cameraMoveToLocation(toLocation: location)
}func authorizattionStatusDidChanged(isAccessGranted: Bool) {// implement some reaction on chnging authorization status}}
Done!
Let’s run the App and see whats happen:
Great!