2017-04-20 86 views
1

我试图用Apple的地图来显示两个地方的路线。如何设置MKPlacemark的显示名称?

对于这两个地方,我有名字和坐标。

MKMapItem *currentLocation = [[MKMapItem alloc] 
    initWithPlacemark:[[MKPlacemark alloc] 
         initWithCoordinate:paramModel.fromCoordinate2D 
        addressDictionary:nil]]; 
MKMapItem *toLocation = [[MKMapItem alloc] 
    initWithPlacemark:[[MKPlacemark alloc] 
         initWithCoordinate:paramModel.toCoordinate2D 
         addressDictionary:nil]]; 
return [MKMapItem openMapsWithItems:@[ currentLocation, toLocation ] 
        launchOptions:@{ 
         MKLaunchOptionsDirectionsModeKey : 
          MKLaunchOptionsDirectionsModeDriving 
        }]; 

这些名字存储在paramModel里面。

我认为这可以通过使用addressDictionary来实现?我尝试了kABPersonAddressStreetKeykABPersonAddressCityKey,但两者都不会显示在最终路线视图中。

回答

0

尝试创建MKPlacemark作为一个变量,然后修改标题字段上的变量,像这样:

MKPlacemark* placemark = [[MKPlacemark alloc] 
        initWithCoordinate:paramModel.fromCoordinate2D 
       addressDictionary:nil]]; 
placemark.title = @"Some Title"; 
placemark.subtitle = @"Some subtitle"; 

然后设置变量作为地图项目构造函数中的参数。

+0

对不起,但'title'和'subtitle'字段似乎是'readonly'? –

0

只要发现我可以直接修改name字段MKMapItem

MKMapItem *currentLocation = [[MKMapItem alloc] 
    initWithPlacemark:[[MKPlacemark alloc] 
        initWithCoordinate:paramModel.fromCoordinate2D 
       addressDictionary:nil]]; 
currentLocation.name = paramModel.fromName;