【问题标题】:How to set the display name for MKPlacemark?如何设置 MKPlacemark 的显示名称?
【发布时间】:2017-04-20 11:35:41
【问题描述】:

我正在尝试使用 Apple 的地图显示两个地方的路线。

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

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,但都不会出现在最终的路线视图中。

【问题讨论】:

    标签: ios mapkit mkmapitem clplacemark


    【解决方案1】:

    发现我可以直接修改MKMapItemname字段。

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

    【讨论】:

      【解决方案2】:

      尝试将您的 MKPlacemark 创建为变量,然后像这样修改该变量上的标题字段:

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

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

      【讨论】:

      • 很抱歉,titlesubtitle 字段似乎是 readonly?
      猜你喜欢
      • 2020-08-03
      • 1970-01-01
      • 2019-08-09
      • 1970-01-01
      • 1970-01-01
      • 2016-11-24
      • 2022-01-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多