无法循环地理编码? [英] Can't loop geocoding?
问题描述
我正在使用一个使用我之前构建的数据库的循环。这是代码:
NSString * address = [NSString stringWithFormat:@%@,Nederland,[info2 objectForKey:@ stadsnaam]];
[self.geocoder geocodeAddressString:address completionHandler:^(NSArray * placemarks,NSError * error){
CLPlacemark * placemark = [placemarks objectAtIndex:0];
CLLocation * location = placemark.location;
CLLocationCoordinate2D firstLocation = location.coordinate;
NSLog(@%f,%f,firstLocation.latitude,firstLocation.longitude);
}];
这段代码在for循环中。但第一次运行,它只返回0.0000
第二次循环被激活(我确定它运行多次),它只返回当前位置和FIRST城市之间的距离。
$ b 应用程序从这段代码获取城市名称: [NSString stringWithFormat:@ %@,Nederland,[info2 objectForKey:@stadsnaam]]
我想避免使用谷歌API,因为我会做出超过一天的最大请求可能XD
任何帮助表示赞赏,请告诉我,如果有什么不是' t完全清楚,并提前感谢!
您需要阅读 的文档
- geocodeAddressString:completionHandler::
发起前向地理编码请求后,或反向地理编码请求。
您可以使用CLGeocoder的地理编码
属性来确定是否正在进行地理编码操作。
At the moment I'm working on an application for the iPad, which at a certain point should show a list of cities with next to these cities the distance from the users current location.
I'm using a loop which uses a database I built earlier. This is the code:
NSString *address = [NSString stringWithFormat:@"%@, Nederland", [info2 objectForKey:@"stadsnaam"]];
[self.geocoder geocodeAddressString:address completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
CLLocation *location = placemark.location;
CLLocationCoordinate2D firstLocation = location.coordinate;
NSLog(@"%f,%f", firstLocation.latitude, firstLocation.longitude);
}];
This piece of code is inside a for loop. But the first time it is run, it just returns 0.0000
The second time the loop is activated (and I'm sure it runs more than one time) it returns only the distance between the current location and the FIRST city.
The app gets the city names from this piece of code:[NSString stringWithFormat:@"%@, Nederland", [info2 objectForKey:@"stadsnaam"]]
Which I verified and works. I would like to avoid using the Google API because I will be making more than the maximum request a day probably XD
Any help is appreciated, please inform me if anything isn't completely clear and thanks in advance!
You need to read the documentation for -geocodeAddressString:completionHandler:
:
After initiating a forward-geocoding request, do not attempt to initiate another forward- or reverse-geocoding request.
You can use CLGeocoder's geocoding
property to determine whether a geocoding operation is in progress.
这篇关于无法循环地理编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!