iOS MapKit-显示注释以包括缩放时的用户位置

iOS MapKit-显示注释以包括缩放时的用户位置,ios,swift,swift3,mapkit,Ios,Swift,Swift3,Mapkit,我在ViewDidDisplay中有一个网络调用,它检索包含要在地图上显示的位置信息的站点列表。调用showAnnotations时,地图将缩放以显示除用户位置以外的所有注释 其他堆栈溢出问题说调用带有动画标志的showAnnotations为true,但这不起作用 // Assign new sites self.sites = newSites // Show annotations on map self.mapView.showAnnotations(self.sites, anima

我在ViewDidDisplay中有一个网络调用,它检索包含要在地图上显示的位置信息的站点列表。调用showAnnotations时,地图将缩放以显示除用户位置以外的所有注释

其他堆栈溢出问题说调用带有动画标志的showAnnotations为true,但这不起作用

// Assign new sites
self.sites = newSites

// Show annotations on map
self.mapView.showAnnotations(self.sites, animated: true)

为什么只缩放显示站点而不显示用户的位置?

问题是showAnnotations会将注释添加到地图中,并且只缩放显示这些注释-这非常有意义。那么我们怎样才能包括用户的位置呢?我使用了以下代码:

// Assign new sites
self.sites = newSites

// Add new annotations
self.mapView.addAnnotations(self.sites)

// Show all annotations to include current user location
self.mapView.showAnnotations(self.mapView.annotations, animated: true)

这里的关键部分是首先使用mapView.addAnnotations添加注释,然后在包括用户位置的所有mapView注释上调用mapView.showAnnotations(…,动画:true)。

值得一提的是,
mapView.showUserLocation=true
必须在
showAnnotations