如何在 iPhone 版 Google 地图中获取每个图钉的描述
我的 MKPointAnnotation
有问题。我想创建这样的 iPhone 应用程序:
- 在 Google 地图中显示图钉
- 在每个图钉上显示说明,从
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:
- Show a pin in Google Maps
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将在我自己的类中采用 MKAnnotation 协议,并简单地覆盖
并实现
我的类还将有一个初始化程序,它获取它需要的所有数据(来自您提到的数组)。
迭代时,我将创建自己的对象,然后将它们添加到注释的集合。
干杯...
I would adopt the MKAnnotation protocol in my own class and simply override the
and implement
My class would also have an initialiser that takes all the data it needs (from the array you mentioned)
When iterating I would create my own objects and then add them to the collection of annotations.
Cheers...