MrS*_*oot 3 objective-c geocode ios5 clgeocoder
我正在连接到一个基本上返回XML的远程Web服务.然后我将该XML解析为Property对象(想想真实的状态)
但现在,Web服务仅返回每个属性的邮政编码.它没有提供我需要在地图中放置注释的坐标.我能够为邮政编码提供地址代码.但是,我的问题是它不允许我做多个请求
这是我的代码
- (void)processProperties:(Property *)property {
[geocoder geocodeAddressString:property.postalCode
completionHandler:^(NSArray* placemarks, NSError* error){
placemark = [placemarks lastObject];
for (CLPlacemark* aPlacemark in placemarks)
{
[sublet setLatitude:aPlacemark.location.coordinate.latitude];
[sublet setLongitude:aPlacemark.location.coordinate.longitude];
}
}];
}
- (void)addAnnotations:(NSArray *)objects {
CLLocationDegrees lat;
CLLocationDegrees longitude;
CLLocationCoordinate2D mCoords;
NSString *fullAddress;
// Add the annotations found nearby
for (Property *property in objects) {
[self processProperties:property];
lat = property.latitude;
longitude = property.longitude;
fullAddress = [NSString stringWithFormat:@"%@ %@ %@", property.houseNumber, @" ", property.streetName];
[self createAnnotationWithCoords:mCoords :fullAddress :[NSString stringWithFormat:@"$%.2f", property.rent]];
}
zoomLevel = 0.1;
mCoords = CLLocationCoordinate2DMake(lat,longitude);
MKCoordinateRegion region = MKCoordinateRegionMake(mCoords,MKCoordinateSpanMake(zoomLevel,zoomLevel));
[self.mapView setRegion:region animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
出于某种原因,它只是对1个属性进行地理编码.不会相应地循环.
有什么想法吗?
在前向地理功能上使用此功能.地理编码器需要再次发布和初始化以启动新地址,希望这会有所帮助.
- (void)processProperties:(Property *)property {
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:property.postalCode
completionHandler:^(NSArray* placemarks, NSError* error){
placemark = [placemarks lastObject];
for (CLPlacemark* aPlacemark in placemarks)
{
[sublet setLatitude:aPlacemark.location.coordinate.latitude];
[sublet setLongitude:aPlacemark.location.coordinate.longitude];
}
[geocoder release];
}];
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2223 次 |
最近记录: |