【发布时间】:2011-01-16 23:19:31
【问题描述】:
如何在我的应用程序中获得这种地图视图?
有什么例子吗?
【问题讨论】:
标签: iphone
如何在我的应用程序中获得这种地图视图?
有什么例子吗?
【问题讨论】:
标签: iphone
您需要使用 MKMapView。对于弹出窗口,您需要一个注释。查看 MKMapView 文档应该会让您走得很远..
【讨论】:
您应该使用 MKMapView - 正如 donkim 提到的,在 MKMapView 上做一些阅读,这会让您走得很远。您可以将 MKAnnotations 用于地图注释。如果您想使用自定义图像进行注释,您可以谷歌搜索“自定义注释”。
您可以参考我不久前发布的this 帖子以了解内存泄漏,但它几乎包含在地图上显示注释的代码。我也是从网上借来的代码...
【讨论】:
我想我需要在
中调用这个...//NSString *latlong = [[NSString stringWithFormat:@"%f, %f", 52.366428f,4.896349f] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//........for destination location.
//NSString *dlatlong = [[NSString stringWithFormat:@"%f, %f", coordinate.latitude, coordinate.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//for the current location. this. where coordinate is CLLocationManager2D.
//NSString *url = [NSString stringWithFormat: @"http://maps.google.com/maps?ll=%@&saddr=%@&daddr=%@",
//latlong, latlong, dlatlong];
不需要使用 mkmapkit。
【讨论】:
有一种更简单的方法可以在地图上显示位置,但是这种方法不会在您的应用程序中实现地图视图,但会打开地图应用程序。
[[UIApplication sharedApplication] openUrl:@"http://maps.google.com/maps?q=Oslo"];
在 q- 参数键之后,您可以编写与通常在 google 地图中指定地址相同的字符串。阅读 UIApplication 类的文档以获取更多信息。请注意,这也会自动为该位置添加注释。
只需提及这一点,因为如果其他人不需要应用程序中的地图,他们可能会觉得这很有用。
这里是其他参数的列表:
【讨论】: