iPhone SDK MKPlacemark

发布于 2024-11-28 19:09:42 字数 1298 浏览 1 评论 0原文

我需要 MapKit 框架方面的帮助。我是 iPhone 开发新手。 我有一个 webview,它从带有 3 个参数的 url 加载,如下所示:

在视图控制器的 viewDidLoad 方法中:

NSString *hoUrlString = [NSString stringWithFormat:@"http://fastenergy.clavis-solutions.de/?iwidth=%@&iheight=%@&zipcode=%@", hString, wString, zipcode];

我无法获取邮政编码。我在 url 之前调用此方法:

locationController = [[HoCLController alloc] init];
locationController.delegate = self;
[locationController.locationManager startUpdatingLocation];

在 HoCLController.m 的这个方法中

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation

,我调用

MKReverseGeocoder *geocoder = [[MKReverseGeocoder alloc] initWithCoordinate:coord];
    [geocoder setDelegate:self];
    [geocoder start];

然后我有这 2 个方法

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {
    NSLog(@"The geocoder has returned: %@", placemark.postalCode);

}

-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error {
    NSLog(@"Error: %@", [error description]);
}

问题是,如何获取 url 中的邮政编码?

谢谢你并请帮忙。

I need help with the MapKit framework. I am new to iPhone development.
I have a webview that loads from a url with 3 params like this:

in viewDidLoad method from the view controller:

NSString *hoUrlString = [NSString stringWithFormat:@"http://fastenergy.clavis-solutions.de/?iwidth=%@&iheight=%@&zipcode=%@", hString, wString, zipcode];

I can't get the zipcode. I am calling this before the url:

locationController = [[HoCLController alloc] init];
locationController.delegate = self;
[locationController.locationManager startUpdatingLocation];

and in this method from HoCLController.m

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation

, I call

MKReverseGeocoder *geocoder = [[MKReverseGeocoder alloc] initWithCoordinate:coord];
    [geocoder setDelegate:self];
    [geocoder start];

Then I have these 2 methods

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {
    NSLog(@"The geocoder has returned: %@", placemark.postalCode);

}

-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error {
    NSLog(@"Error: %@", [error description]);
}

The question is , how can I get the zipcode in the url?

Thank you and please help.

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

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

发布评论

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

评论(3

雪花飘飘的天空 2024-12-05 19:09:42

你的问题中已经有了答案。
placemark.postalcode 由您的邮政编码组成。
只要确保所有变量都包含正确的值即可。

zipcode = placemark.postalCode;

如果我答对了你的问题,应该是答案。

You have already the answer in your question.
placemark.postalcode consists of your zipcode.
Just make sure, that all your variables consist the right value.

zipcode = placemark.postalCode;

Should be the answer, if i get your question right.

病毒体 2024-12-05 19:09:42
MKReverseGeocoder *geocoder = [[MKReverseGeocoder alloc] initWithCoordinate:coord]; 

您必须在此方法中传递坐标。所以检查坐标是否不为零。我想这就是你想要的。

MKReverseGeocoder *geocoder = [[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate];
MKReverseGeocoder *geocoder = [[MKReverseGeocoder alloc] initWithCoordinate:coord]; 

You have to pass coordinate in this method. So check if coord is not nil.I guess this is what you want.

MKReverseGeocoder *geocoder = [[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate];
温柔一刀 2024-12-05 19:09:42

哦好吧,忘了吧。。
我错过了一些东西,抱歉

你是CLLocationManager的子类吗???
如果没有,为什么要这样分配:locationManager = [[HoCLController alloc] init];而不是这样:self.locationManager = [[CLLocationManager alloc] init];如果我弄错了,我很抱歉,但我想我正在给你答案..

Oh Ok, forget it..
I miss something, sorry

Are you subclassing CLLocationManager ???
If not, why are you allocating like this: locationManager = [[HoCLController alloc] init]; instead of this:self.locationManager = [[CLLocationManager alloc] init]; I'm sorry if I'm getting something wrong, but think i'm giving you the answer..

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