cllocation 和 mkreversegeocoder

发布于 2024-08-29 00:56:47 字数 1612 浏览 4 评论 0原文

我尝试使用 cllocation 和 mkreversegeocoder 检索城市名称。 在我的 viewdidload 方法中,我 istance cllocationmanager:

self.locManager = [[CLLocationManager alloc] init];
locManager.delegate = self;
locManager.desiredAccuracy = kCLLocationAccuracyBest;
[locManager startUpdatingLocation];

和之后:

- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation 
*)newLocation
fromLocation:(CLLocation *)oldLocation {
//some code to retrieve my information

MKReverseGeocoder *geoCoder = [[MKReverseGeocoder alloc]     
initWithCoordinate:newLocation.coordinate ];
geoCoder.delegate = self;
[geoCoder start];
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark  
*)placemark
{
MKPlacemark *myPlacemark = placemark;
citta.text = [placemark locality];
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{
citta.text =@ "Unknow";

应用程序仅在我第一次获得值时才起作用。在第二次应用程序崩溃时。 我认为是因为地理编码器已启动,并且我认为我必须运行一个且只有一个实例。 (但我真的对此不确定......)。我可以通过什么方式控制地理编码器的运行?

我发现我可以使用 cllocationcoordinate2d 在我的 viewdidload 中使用 mkreversegeocoder 但是...我可以通过哪种方式检索 newlocation.coordinate ?

我已经部分解决了将地理编码器声明为类变量并检查

if (self.geocoder != nil) {
   [geocoder release];
}

但是....如果在我

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

或我的

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailedWithError:(@NSError 
*)error

我中释放或取消我的对象? 我感觉自己好傻 :D

i'm try to retreiving city name with cllocation and mkreversegeocoder.
in my viewdidload method i istance cllocationmanager:

self.locManager = [[CLLocationManager alloc] init];
locManager.delegate = self;
locManager.desiredAccuracy = kCLLocationAccuracyBest;
[locManager startUpdatingLocation];

and after:

- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation 
*)newLocation
fromLocation:(CLLocation *)oldLocation {
//some code to retrieve my information

MKReverseGeocoder *geoCoder = [[MKReverseGeocoder alloc]     
initWithCoordinate:newLocation.coordinate ];
geoCoder.delegate = self;
[geoCoder start];
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark  
*)placemark
{
MKPlacemark *myPlacemark = placemark;
citta.text = [placemark locality];
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{
citta.text =@ "Unknow";

Application works only the first time i get my value. on the second time app crash.
I think is because geocoder is started and i think i must have one and only one istance running. (but i'm really not shure of this...). in which way i can controll geocoder is running?

I've see that i can istance mkreversegeocoder in my viewdidload using cllocationcoordinate2d but ... in which way i can retreive newlocation.coordinate?

I've partially resolve declaring geocoder as class variable and checking

if (self.geocoder != nil) {
   [geocoder release];
}

but.... if in my

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

or in my

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailedWithError:(@NSError 
*)error

i release or cancel my object?
I'm feeling so stupid :D

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北方。的韩爷 2024-09-05 00:56:47

不要将反向地理编码器创建为局部变量。

查看 CurrentAddress 示例应用中的 MKReverseGeocoder 示例由苹果公司提供。请参阅 MapViewController.h 和 MapViewController.m。

在您的代码中遵循相同的模式。

Don't create the reverse geocoder as a local variable.

Look at the MKReverseGeocoder example in the CurrentAddress sample app provided by Apple. See MapViewController.h and MapViewController.m.

Follow the same pattern in your code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文