pgruber pgruber - 1 year ago 179
Swift Question

Mapbox - setCenterCoordinate is deselecting annotations

I'm trying out mapbox (using the ios sdk) and I've run into a problem that I think I've narrowed down pretty far. This is my code:

func centerMap(location: CLLocationCoordinate2D) {
zoomLevel: 14,
animated: true)

func mapView(mapView: MGLMapView, didDeselectAnnotation annotation: MGLAnnotation) {
dealDetails.hidden = false

func mapView(mapView: MGLMapView, didUpdateUserLocation userLocation: MGLUserLocation?) {
if let currentLocation = userLocation?.coordinate {

If I don't re-center the map when the user's location is updated (i.e., just commenting out the
call) then the annotation remains selected. Re-centering the map calls the
function, and I can't figure out how to keep that annotation selected. Any help is appreciated!

Answer Source

I don't think there's any way around that if you update the center coordinate. You'd have to re-select the annotation. However, you probably don't need to do that. If you set the userTrackingMode on the map view to .Follow, it should re-center automatically.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download