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
first add the following to your info.plist
second go to https://developers.google.com/maps/documentation/ios-sdk/start and follow the steps till step 5
last thing to do after you set up every thing is to go to your ViewController and paste the following
import UIKit
import GoogleMaps
class ViewController: UIViewController,CLLocationManagerDelegate {
//Outlets
@IBOutlet var MapView: GMSMapView!
//Variables
var locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
initializeTheLocationManager()
self.MapView.isMyLocationEnabled = true
}
func initializeTheLocationManager() {
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
var location = locationManager.location?.coordinate
cameraMoveToLocation(toLocation: location)
}
func cameraMoveToLocation(toLocation: CLLocationCoordinate2D?) {
if toLocation != nil {
MapView.camera = GMSCameraPosition.camera(withTarget: toLocation!, zoom: 15)
}
}
}
( don't forget to add a view in the storyboard and connect it to the MapViw)
now you can build and run to see your current location on the google map just like when you open the Google Map App
enjoy coding :)