gpt4 book ai didi

ios - 如何将多个地名转换成坐标?

转载 作者:行者123 更新时间:2023-11-29 11:13:03 25 4
gpt4 key购买 nike

我正在尝试使用以下代码将地理编码 2 地名转发到坐标中:

CLGeocoder *geocoder = [[CLGeocoder alloc] init];

[geocoder geocodeAddressString:place 
inRegion:nil
completionHandler:^(NSArray* placemarks, NSError* error){
NSLog(@"a");
NSLog(@"count %d", [placemarks count]);
for (CLPlacemark* aPlacemark in placemarks) {
CLLocationCoordinate2D coord = aPlacemark.location.coordinate;

NSLog(@"%f, %f", coord.latitude, coord.longitude);
}
}];

[geocoder geocodeAddressString:place
inRegion:nil
completionHandler:^(NSArray* placemarks, NSError* error){
NSLog(@"b");
NSLog(@"count %d", [placemarks count]);
for (CLPlacemark* aPlacemark in placemarks) {
CLLocationCoordinate2D coord = aPlacemark.location.coordinate;

NSLog(@"%f, %f", coord.latitude, coord.longitude);
}
}];

为了简化,我将一个地名转换了两次。当我运行代码时,只有第一个地理编码完成处理程序运行。剩余的地理编码完成处理程序将被忽略。

我想知道为什么会发生这种情况以及如何转换多个地点。

最佳答案

请参阅 Apple 的指南: http://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLGeocoder_class/Reference/Reference.html

Applications should be conscious of how they use geocoding. Here are some rules of thumb for using this class effectively:

1) Send at most one geocoding request for any one user action.

2) If the user performs multiple actions that involve geocoding the same location, reuse the results from the initial geocoding request instead of starting individual requests for each action.

3) When you want to update the user’s current location automatically (such as when the user is moving), issue new geocoding requests only when the user 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 geocoding request per minute.

4) Do not start a geocoding request at a time when the user will not see the results immediately. For example, do not start a request if your application is inactive or in the background.

关于ios - 如何将多个地名转换成坐标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10653819/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com