MKAnnotation的coordinate的边界问题

若MKAnnotation的coordinate的值设置错误会发生下面的类似的异常信息:


An instance 0x5fc5c00 of class Annotation was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info:

<NSKeyValueObservationInfo 0x5fbc560> (

<NSKeyValueObservance 0x5fbc400: Observer: 0x6bf6840, Key path: coordinate, Options: <New: NO, Old: NO, Prior: YES> Context: 0x0, Property: 0x5fbbd60>

)



假设Annotation遵守MKAnnotation协议,在给Annotation对象的coordinate赋值时,要注意:纬度的范围是-90~90, 负值表示南纬;经度的范围是-180~180,负值表示西经。 另外还需主要的是,经纬度是用浮点数表示的,当我们想表示北纬90度时,直接将 90赋予latitude是错误的,因为浮点数不是绝对精确的,得到的纬度值很可能大于90。


float longtitude = [[coordinateArr objectAtIndex:0] floatValue];   //   -180 < latitude < 180

float latitude   = [[coordinateArr objectAtIndex:1] floatValue];   //   -90 < longtitude < 90

Annotation *anno = [[Annotation alloc] init];

anno.coordinate = CLLocationCoordinate2DMake(latitude, longtitude);




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值