代码之家  ›  专栏  ›  技术社区  ›  Idan

IPhone-MKReverseGeocoder-如何确保我有结果回来

  •  0
  • Idan  · 技术社区  · 14 年前

    我尝试的是显示带有城市名称的注释。

    @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
    

    我是这样实施的:

    @implementation MapPoint
    
    @synthesize title,coordinate,cityName;
    
    -(id) initWithCoordinate:(CLLocationCoordinate2D)c tilte:(NSString*)t
    {
        [super init];
        coordinate = c;
        reverseGeo = [[MKReverseGeocoder alloc] initWithCoordinate:c];
        reverseGeo.delegate = self;
        [reverseGeo start];
        [self setTitle:t];
        return self;
    
    }
    
    - (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
    {
        NSString* city = [placemark.addressDictionary objectForKey:(NSString*)kABPersonAddressCityKey];
        NSString* newString = [NSString stringWithFormat:@"city-> %@",city];
        [self setTitle:[title stringByAppendingString:newString]];
    }
    
    -(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{
        NSLog(@"error fetching the placemark");
    }
    
    -(void)dealloc
    {
        [reverseGeo release];
        [cityName release];
        [title release];
        [super dealloc];
    }
    
    @end
    

    -(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];
    
    }
    

    现在,我有两个问题我不确定:

    1 回复  |  直到 14 年前
        1
  •  0
  •   Seamus Campbell    14 年前
    1. 看起来你要为用户的当前位置留下一系列注释?如果要用显示用户所在位置的“面包屑轨迹”来补充常规用户的当前位置注释,则需要等待将该点添加到地图中,直到取回注释为止(如果这是您想要的行为)。我可以通过使管理映射的类成为MKReverseGeocoder委托来实现这一点(并让它设置title属性,然后将注释添加到中的映射 reverseGeocoder:didFindPlacemark )或者向MapPoint类添加一个map引用,并在同一个回调中将其自身添加到map中。

    • When you want to update the location automatically (such as when the user is moving), reissue the reverse-geocoding request only when the user's location has moved a significant distance and after a reasonable amount of time has passed. For example, in a typical situation, you should not send more than one reverse-geocode request per minute.