IPhone-MKReverseGeocoder-如何确保返回结果
我想要达到的是显示带有城市名称的注释 所以我有一个类映射点:IPhone-MKReverseGeocoder-如何确保返回结果,iphone,objective-c,cocoa-touch,mkmapview,mkreversegeocoder,Iphone,Objective C,Cocoa Touch,Mkmapview,Mkreversegeocoder,我想要达到的是显示带有城市名称的注释 所以我有一个类映射点: @interface MapPoint : NSObject<MKAnnotation,MKReverseGeocoderDelegate> { NSString* title; NSString* cityName; CLLocationCoordinate2D coordinate; MKReverseGeocoder* reverseGeo; } @property (nonato
@interface MapPoint : NSObject<MKAnnotation,MKReverseGeocoderDelegate> {
NSString* title;
NSString* cityName;
CLLocationCoordinate2D coordinate;
MKReverseGeocoder* reverseGeo;
}
@property (nonatomic,readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic,copy) NSString* title;
@property (nonatomic,copy) NSString* cityName;
-(id) initWithCoordinate:(CLLocationCoordinate2D)c tilte:(NSString*)t;
@end
然后,在我的CoreLocation委托中,我使用MapPoint如下:
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
MapPoint* mp = [[MapPoint alloc] initWithCoordinate:[newLocation coordinate] tilte:[locationTitleField text]];
[mapView addAnnotation:mp];
[mp release];
}
现在,我有两个问题我不确定:
将reverseGeo作为数据成员是否正确,或者更好的选择是
将其分配到初始值设定项中,并在didFindPlacemark/DidFailWitheror授权中释放它是否可能在那里释放它
那么,当我的注释显示出来时,我如何确保我确定reverseGeo返回时带有一个答案位置标记或错误——不管是什么。
也许等待网络响应是错误的,我应该让它保持这样-我只是不确定网络响应何时/是否会到达,它将相应地更新MapView中的注释视图
请尽可能详细说明。
谢谢
可以将其存储为数据成员
看起来您正在为用户的当前位置留下注释线索?如果要用面包屑轨迹来补充常规用户的当前位置注释,以显示用户的位置,则需要等待将该点添加到地图,直到恢复注释(如果这是您想要的行为)。我可以通过使管理地图的类成为MKReverseGeocoder委托并让它设置title属性,然后在reverseGeocoder:didFindPlacemark中将注释添加到地图中,或者向MapPoint类添加地图引用,并让它在同一回调中将自身添加到地图中来实现这一点
顺便说一下,MKReverseGeocoder的文档包括以下文本:
当您希望自动更新位置时(例如当用户移动时),仅当用户的位置移动了相当长的距离并且经过了合理的时间后,才重新发出反向地理编码请求。例如,在典型情况下,每分钟不应发送多个反向地理编码请求。
这或多或少是我的想法,但后来我开始思考我在帖子中写的东西。1.你看,获取placemark是一个网络请求,我真的想等到我获取了它之后再显示注释吗?如果以后我更新title属性,它会反映在地图视图上吗?2.现在我正在为地图点的每个注释分配一个新的MKReverseGeocoder,这是正确的方法吗?或者有一种方法可以使用同一个,只改变它的坐标?iOS5中不推荐使用MKReverseGeocoder。如果您现在就开始开发应用程序,则应该使用CLGeocoder,否则,您可能需要稍后迁移它。
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
MapPoint* mp = [[MapPoint alloc] initWithCoordinate:[newLocation coordinate] tilte:[locationTitleField text]];
[mapView addAnnotation:mp];
[mp release];
}