Learn Courses My Dashboard

Update map to users location after pan

Hi there,

I followed th tutorial SwiftUI CoreLocation: How to display a map and show the users current location - CodeWithChris and it works.
If i open the app the map is centered to the devices location. While moving around the center follows the position. So far so good.
If i now pan the map manually I have no “way back” to the automatic centering.
My wish is to add a button to center the map the the current location.
But how can I implement it?
Any help is appreciated.


Welcome to the community.

I you are you running the App on a simulator it won’t “follow” your actual location since it has no GPS capability. What you can do is simulate movement by setting the Location in the simulator.

From the Simulator menu select Features > Location and then choose Freeway Drive.

You probably also should change the span values to zoom the map in a lot more. Change them to 0.05 and it will look much better.

If you run the App on your own device and then go for a drive, it will track your movement.