puks1978
puks1978

Reputation: 3697

Keep user location center in Google Maps - Swift

I have implemented Google maps in to a swift project and using locationManager to track and currently print out the users location.

I am also changing the camera position as the user moves around however this seems a bit jerky as the map moves then the blue dot (user location) moves.

Is there a way to keep the user location centered at all times and just have the map move?

Upvotes: 1

Views: 1820

Answers (3)

MacUserT
MacUserT

Reputation: 1953

Plaese, see if this answer helps you. The user location is centered all the time in the example code. There is no camera adustment though, but that shouldn't make a difference.

Hope it helps.

Upvotes: 0

Maryam Fekri
Maryam Fekri

Reputation: 625

you can easily enable

mapView.myLocationEnabled = true

and see this answer for more info to camera updating -> as it shows how to update camera with 2 positions or center a location

Upvotes: 0

Milap Kundalia
Milap Kundalia

Reputation: 1606

let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)        
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
self.map.setRegion(region, animated: true)

Upvotes: -1

Related Questions