等待 MKReverseGeocoder 提供地址
有没有办法等待地理编码器调用 didFailWithError 或 didFindPlaceMark?
我的问题是我必须调用一个接收坐标并返回保存地址的地标的方法。但是当我调用 [myGeocoder start] 代码继续时,我得到一个空地标。
我的代码是:
- (MKPlasemark*) getAddress:(CLLocationCoordinate2D) coordinate
{
[self startGeocoder:coordinate];
return self.foundPlasemark;
}
- (void)reverseGeocoder:(MKReverseGeocoder*)geocoder didFindPlacemark:(MKPlaseMark*)plasemark
{
self.foundPlasemark=plasemark;
}
- (void)reverseGeocoder:(MKReverseGeocoder*)geocoder didFailWithError:(NSError*)error
{
self.foundPlasemark=nil;
}
我尝试执行 sleep() 为什么调用以下方法之一,但它不起作用。
Is there a way to wait for geocoder to invoke didFailWithError or didFindPlaceMark?
My problem is that i have to call a method that receives coordinate and returns placemark holding the address. But when i call [myGeocoder start] code continues and i get an empty placemark.
My code is:
- (MKPlasemark*) getAddress:(CLLocationCoordinate2D) coordinate
{
[self startGeocoder:coordinate];
return self.foundPlasemark;
}
- (void)reverseGeocoder:(MKReverseGeocoder*)geocoder didFindPlacemark:(MKPlaseMark*)plasemark
{
self.foundPlasemark=plasemark;
}
- (void)reverseGeocoder:(MKReverseGeocoder*)geocoder didFailWithError:(NSError*)error
{
self.foundPlasemark=nil;
}
I tryed to perform sleep() whyle one of the following methods invoked, but it didn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你的处理方式是错误的,没有理由阻止,你所要做的就是让该方法返回 void,并在处理地理编码的类中,定义一个具有方法的协议 -( void)didReceivePlacemark:(id)地标,地标可以是nil或某个地标,当地理编码器返回时调用它。您还为您的类创建一个委托属性,以便任何人都可以订阅该协议...然后在调用类中订阅该协议并实现该方法...这里有更多关于 协议
希望有帮助
这是一个例子:
因此,执行地理编码的类的接口将如下所示
然后在实现中您将看到类似这样的内容
在调用类中,您只需设置 GeocoderClass 的委托属性,并实现协议、实现可能看起来像
I think you are going about it the wrong way, there is no reason to block, what you have to do is have that method return void, and in the class that is handling the geocoding, define a protocol that has a method say -(void)didReceivePlacemark:(id)placemark, placemark can be nil or some placemark, and it is called when the geocoder returns. You also make a delegate property for your class so anyone can subscribe to the protocol... Then in the calling class subscribe to the protocol and implement the method...heres a bit more on protocols
Hope that helps
Here is an example:
So the interface of your class that does the geocoding will look something like this
Then in the implementation you would see something like this
In the calling class, all you have to set is the delegate property of the GeocoderClass, and implement the protocol, the implementation might look somethign like