如何在 iPhone 版 Google 地图中获取每个图钉的描述

发布于 2024-10-01 06:10:04 字数 817 浏览 1 评论 0原文

我的 MKPointAnnotation 有问题。我想创建这样的 iPhone 应用程序:

  1. 在 Google 地图中显示图钉
  2. 在每个图钉上显示说明,从 NSMutableArray 中提取该说明。

所以,我的问题是,如何在每个引脚上显示描述?

这是我的代码:

 NSMutableArray *points = [[NSMutableArray alloc] init];
 for(int i=0; i < [dataTable count]; i++) {
   MKPointAnnotation *point =[[MKPointAnnotation alloc] init];
   CLLocationCoordinate2D coordinate;
   coordinate.latitude = [[[dataTable objectAtIndex:i] objectForKey:@"latitude"] floatValue];
   coordinate.longitude = [[[dataTable objectAtIndex:i] objectForKey:@"longitude"] floatValue];
   [point setCoordinate:coordinate];
   [point setTitle:[[dataTable objectAtIndex:i] objectForKey:@"name"]]; //-- name of pin
   [points addObject:point];
 }
 [map addAnnotations:points];

I have a problem with MKPointAnnotation. I want to create my iPhone application like this:

  1. Show a pin in Google Maps
  2. Show a description on each pin, pulling that description from a NSMutableArray.

So, My question is, how do I show a description on each pin?

This is my code:

 NSMutableArray *points = [[NSMutableArray alloc] init];
 for(int i=0; i < [dataTable count]; i++) {
   MKPointAnnotation *point =[[MKPointAnnotation alloc] init];
   CLLocationCoordinate2D coordinate;
   coordinate.latitude = [[[dataTable objectAtIndex:i] objectForKey:@"latitude"] floatValue];
   coordinate.longitude = [[[dataTable objectAtIndex:i] objectForKey:@"longitude"] floatValue];
   [point setCoordinate:coordinate];
   [point setTitle:[[dataTable objectAtIndex:i] objectForKey:@"name"]]; //-- name of pin
   [points addObject:point];
 }
 [map addAnnotations:points];

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

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

发布评论

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

评论(1

音栖息无 2024-10-08 06:10:04

我将在我自己的类中采用 MKAnnotation 协议,并简单地覆盖

 - (NSString) title

并实现

 - (CLLocationCoordinate2D) coordinate {
    CLLocationCoordinate2D theCoordinate;
    theCoordinate.latitude = self.latitude;
    theCoordinate.longitude = self.longitude;
    return theCoordinate; 
 }

我的类还将有一个初始化程序,它获取它需要的所有数据(来自您提到的数组)。

- (id) initWithTitle:(NSString *)title_ andLatitude:(CLLocationDegrees)latitude_ andLongitude:(CLLocationDegrees)longitude_;

迭代时,我将创建自己的对象,然后将它们添加到注释的集合。

干杯...

I would adopt the MKAnnotation protocol in my own class and simply override the

 - (NSString) title

and implement

 - (CLLocationCoordinate2D) coordinate {
    CLLocationCoordinate2D theCoordinate;
    theCoordinate.latitude = self.latitude;
    theCoordinate.longitude = self.longitude;
    return theCoordinate; 
 }

My class would also have an initialiser that takes all the data it needs (from the array you mentioned)

- (id) initWithTitle:(NSString *)title_ andLatitude:(CLLocationDegrees)latitude_ andLongitude:(CLLocationDegrees)longitude_;

When iterating I would create my own objects and then add them to the collection of annotations.

Cheers...

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