I am using Google maps sdk of iOS(Swift).
Has anyone know how to \"Show my current location on google maps, when I open the ViewController\"?
Actually it jus
You can use RxCoreLocation:
import UIKit
import GoogleMaps
import RxCoreLocation
import RxSwift
class MapViewController: UIViewController {
private var mapView: GMSMapView?
private let disposeBag = DisposeBag()
private let manager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
manager.requestWhenInUseAuthorization()
manager.startUpdatingLocation()
let camera = GMSCameraPosition.camera(withLatitude: 0, longitude: 0, zoom: 17.0)
mapView = GMSMapView.map(withFrame: .zero, camera: camera)
view = mapView
manager.rx
.didUpdateLocations
.subscribe(onNext: { [weak self] in
guard let location = $0.locations.last else { return }
let camera = GMSCameraPosition.camera(withLatitude: location.coordinate.latitude, longitude: location.coordinate.longitude, zoom: 17.0)
self?.mapView?.animate(to: camera)
self?.manager.stopUpdatingLocation()
})
.disposed(by: disposeBag)
}
}