【问题标题】:MKMapItem with specific Location具有特定位置的 MKMapItem
【发布时间】:2012-09-23 11:05:20
【问题描述】:

如何启动 iOS6 的默认地图应用并将自定义位置传递给它?

例如:

[[MKMapItem setLocation:MyLocation] openInMapsWithLaunchOptions:nil];

我按照此处的示例进行操作,但无法弄清楚。 How can I launch the Google Maps iPhone application from within my own native application?

【问题讨论】:

  • 您打开具有特定位置的 MKMapItem。您可以使用用户位置,也可以使用 MKPlacemark 定义的位置。你遇到了什么问题?
  • 好的,谢谢,我是 xcode 的新手。如何设置地标?例如这些坐标?纬度 = 51.455919;经度 = 6.746442;谢谢:)
  • MKPlacemark *placemark=[[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(51.455919, 6.746442) addressDictionary:yourLocationAddressDictionary];
  • 好的,谢谢 :) 现在我的代码是:MKPlacemark *placemark=[[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(51.455919, 6.746442) addressDictionary:yourLocationAddressDictionary]; [[MKMapItem setLocation:placemark]openInMapsWithLaunchOptions:nil];但我收到 2 个错误 1.“使用未声明的标识符 'yourLocationAddressDictionary'” 2.“选择器 'setLocation' 没有已知的类方法”
  • 您需要创建一个包含地址信息的字典。请注意,要创建此字典,您需要使用地址簿中的键。看看我创建的一个字典: NSDictionary *addressDictionary=@{(NSString *)kABPersonAddressStreetKey : yourLocationStreet, (NSString *)kABPersonAddressCityKey : yourLocationCity, (NSString *)kABPersonAddressStateKey : yourLocationState, (NSString *)kABPersonAddressZIPKey : yourLocationPostalCode, (NSString * )kABPersonAddressCountryKey : yourLocationCountry};

标签: objective-c iphone xcode mkmapitem


【解决方案1】:

以下是使用自定义位置打开地图本机应用程序的代码:

double latitude = 35.0;
double longitude = 1.0;
MKPlacemark *placemark = [[[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(latitude, longitude) addressDictionary:nil] autorelease];
MKMapItem *mapItem = [[[MKMapItem alloc] initWithPlacemark:placemark] autorelease];
[mapItem setName:@"Name of your location"];
[mapItem openInMapsWithLaunchOptions:nil];

【讨论】:

    猜你喜欢
    • 2012-08-02
    • 2014-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-05
    • 2023-01-19
    • 1970-01-01
    相关资源
    最近更新 更多