所以实际上我有一个类似的问题,我在How to get iPhone Maps app blue dot with light blue field for current location?找到了它,我尝试了这个解决方案,但它不起作用,这就是为什么我的下一个问题的时间......
我的ios swift应用程序中有一个地图视图,我将它集中在用户的位置。到目前为止,它工作得很好,但位置标有红色针脚,而不是我希望我想要这个典型的苹果蓝点,周围有一个字段。我的代码如下:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
mapView.delegate = self
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let coordinateRegion = MKCoordinateRegionMakeWithDistance(appDelegate.getLocation().coordinate, 500, 500)
mapView.setRegion(coordinateRegion, animated: true)
mapView.showsUserLocation = true
print("MapEvents: \(appDelegate.getLatitude()), \(appDelegate.getLongitude())")
//this prints correct GPS coords
}
所以我做错了什么?
====编辑
在评论部分中关注艾哈迈德的线索 - 是的,我实施了这个方法:
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
var reuseId = ""
if annotation.isKindOfClass(FBAnnotationCluster) {
reuseId = "Cluster"
var clusterView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
clusterView = FBAnnotationClusterView(annotation: annotation, reuseIdentifier: reuseId, options: nil)
return clusterView
} else {
reuseId = "Pin"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView!.calloutOffset = CGPoint(x: -5, y: 5)
pinView!.canShowCallout = true
pinView!.rightCalloutAccessoryView = UIButton(type: .DetailDisclosure) as UIView
return pinView
}
}
原因是因为我正在使用本教程https://github.com/ribl/FBAnnotationClusteringSwift
中的标记聚类当我评论这个方法时,我看到了蓝点,这很棒,但现在我需要将旧代码带回来 - 有没有办法可以使用两种功能(聚类和蓝点)?那么我应该如何修改注释方法的视图呢?
非常感谢!
答案 0 :(得分:1)
在MKMapView viewForAnnotation委托方法中,如果注释的类型是MKUserLocation,则返回nil。
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation { return nil }
var reuseId = ""
if annotation.isKindOfClass(FBAnnotationCluster) {
reuseId = "Cluster"
var clusterView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
clusterView = FBAnnotationClusterView(annotation: annotation, reuseIdentifier: reuseId, options: nil)
return clusterView
} else {
reuseId = "Pin"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView!.calloutOffset = CGPoint(x: -5, y: 5)
pinView!.canShowCallout = true
pinView!.rightCalloutAccessoryView = UIButton(type: .DetailDisclosure) as UIView
return pinView
}
}