Ios 在带有位置的地图上查找注释
当我在地图上添加注释时,我想突出显示它。Ios 在带有位置的地图上查找注释,ios,swift,xcode6,Ios,Swift,Xcode6,当我在地图上添加注释时,我想突出显示它。 我知道我必须使用 mapView1.选择注解(注解:MKAnnotation!,动画:Bool) 但是我无法获取MKAnnotation对象,我所拥有的只是注释的位置(CLLocationCoordinate2D) 我的问题是,我如何知道他的位置来获得特定的注释 编辑:理论上找到了解决方案,但有一个bug: 对于self.mapView1.annotations as中的注释![注释]{ println(“”) 设annotLatitude=annot
我知道我必须使用
mapView1.选择注解(注解:MKAnnotation!,动画:Bool)
但是我无法获取MKAnnotation对象,我所拥有的只是注释的位置(CLLocationCoordinate2D)
我的问题是,我如何知道他的位置来获得特定的注释
编辑:理论上找到了解决方案,但有一个bug:
对于self.mapView1.annotations as中的注释![注释]{
println(“”)
设annotLatitude=annotation.coordinate.latitude
设annotLongitude=annotation.coordinate.longitude
让eventLatitude=self.appDel!.lastEventCoords.latitude
让eventlongide=self.appDel!.lastEventCoords.longide
println(“annotLatitude:(annotLatitude),annotLongitude:(annotLongitude)”)
println(“事件纬度:(事件纬度),事件经度:(事件经度)”)
if(annotLatitude==eventLatitude&&annotLongitude==eventLongitude){
self.lastAnnotationAdded=注释
println(“位置等于”)
self.mapView1.selectAnnotation(self.lastAnnotationAdded!,动画:true)
打破
}
输出:
注释纬度:47.4799380142289,注释经度:-0.44762351737708
事件纬度:47.4799380142289,事件经度:-0.44762351737708
纬度和经度是完全相同的,但“如果”循环没有执行!有时它工作,但有时不工作。这怎么可能
EDIT2:问题已解决要比较坐标,我必须先用func tronc()截短它们。MKMapView有一个注释列表,它的
注释属性。因此,仔细查看这些注释,直到找到您想要的(具有正确坐标的).奇怪的bug补充道,有时循环不会执行,尽管比较的值完全相等,因为=
并不意味着你认为它是什么。这些是双值;你无法使用=
可靠地比较它们。对于任何搜索者来说:trunc(annotLatitude)
就是他所说的