English 中文(简体)
MK ReverseGeocoder方法是否单独使用?
原标题:Is MKReverseGeocoder delegate method working on separate thread?

I am trying draw route between two location.For that i have two instance of CLLocation startPoin,endPoind. I want to convert this two location two corresponding Location Address.After that i want to fetch all route points from Google map webservice. So did the following code.

- (void)viewDidLoad{
    [super viewDidLoad];
    locations =[[NSMutableArray alloc]initWithCapacity:2];//For location Name 
    [self.mapView_MP setMapType:MKMapTypeStandard];
    [self.mapView_MP setZoomEnabled:YES];
    [self.mapView_MP setScrollEnabled:YES];
    [self update:startPoint];  //MKReverseGeocoder start point  
    [self update:endPoint];    //MKReverseGeocoder end point

    [self updateRoute];

}

- (void)update:(CLLocation*)loc{
    MKReverseGeocoder *geoCoder = [[MKReverseGeocoder alloc] initWithCoordinate:loc.coordinate];


    geoCoder.delegate = self;
    [geoCoder start];

}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{

    NSMutableDictionary *cplace=[[NSMutableDictionary alloc]initWithDictionary:[placemark addressDictionary]];

   // NSLog(@"The geocoder has returned: %@", [cplace objectForKey:@"FormattedAddressLines"] );
   // NSLog(@"The geocoder has returned: %@", [cplace objectForKey:@"Street"] );
    [locations addObject:[cplace objectForKey:@"SubAdministrativeArea"]];
     NSLog(@"The geocoder has returned: %@", locations );
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
{
    NSLog(@"reverseGeocoder:%@ didFailWithError:%@", geocoder, error);
}

- (void)updateRoute {

    self.responseData=[NSMutableData data];  
    NSLog(@" string Formate.................................===%@",locations);   

    NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=%@&destination=%@&mode=driving&sensor=false", [locations objectAtIndex:0],[locations objectAtIndex:1]]]];
    [[NSURLConnection alloc] initWithRequest:request delegate:self];    
}

鉴于DidLoad i正在按顺序排列方法。

[self update:startPoint];      //MKReverseGeocoder start point  
    [self update:endPoint];    //MKReverseGeocoder end point           
    [self updateRoute];

but unfortunately [self updateRoute]; is executing first compare to MKReverseGeocoder delegate method. there for the location array is null in side this method. Getting EXEBADACCESS. how can i over come this value. Inside MKReverseGeocoder delegate method i got location name. the Delegate methods is executing any other thread.

最佳回答

<代码>MKReverseGeocoder is deprecated in令5, 因此,你可能使用CLGeocoder

除此以外,如文件所示,<代码><>start>/code>方法为asynchronous。 这必然意味着,你在获得结果之前通常会回来。

您需要跟踪您的地理编码。 两种方法都已完成。

问题回答

无论它是否在另一条read子上执行,都确实如此。 重要的是,在得到答复时,你可以控制。

你应该有某种逻辑来说,“如果我对开端和终点航道都具有价值,那么,请我打上<条码>更新<>>。 您可以核实<条码>起始点<>。 当你获得<条码>末<><>>>>>>(反之亦然)的价值时,即设定变量,然后才称为<条码>更新<><>>>。

如果你仍然希望使用这一术语,那么,......你应称你的<条码>[自我更新];,载于<条码>-(避免)反转的Geocoder:MKReverseGeocoder*)

这样,当你们有两种价值观时,就将叫作国家措施。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签