My Locations: showUser()


In chapter 29, in viewDidLoad(), instead of showLocations(), I want to showUser() to show user’s location to start with. Here is what I did:

override func viewDidLoad() {
// if !locations.isEmpty {
// showLocations()
// }

However, the above modification does not quite work as I wanted. The map zoom in to an unknown location if I switch from other Tabs to Map Tab.

After that, if I tap the showUser Button, it worked just fine by showing my location

I have also tried putting showUser() to viewDidAppear and viewWillAppear() as well but that didn’t help either

Can you let me know how to fix this problem ?

Thank you

My guess would be that this is due to the initial user location (at the time of the view loading for the first time) is incorrect since the map has not fetched an updated location yet. You might want to wait for a little while after the view appears to call showUser.

In order to do that though, you will need to look at the documentation and/or examples for either NSTimer or GCD (Grand Central Dispatch) and figure out what you need to do since I don’t believe we cover that in the book …

1 Like

Thank you Fahim,

Per your suggestion, I put a 0.5s timer and it works !


This topic was automatically closed after 166 days. New replies are no longer allowed.