我正试着用苹果的地图显示两个地方的路线。
对于这两个地方,我有名字和坐标。
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来实现。我尝试了kABPersonAddressStreetKey和kABPersonAddressCityKey,但它们都不会出现在最终的路由视图中。
发布于 2017-04-21 11:41:03
只要知道我可以直接修改MKMapItem的name字段即可。
MKMapItem *currentLocation = [[MKMapItem alloc]
initWithPlacemark:[[MKPlacemark alloc]
initWithCoordinate:paramModel.fromCoordinate2D
addressDictionary:nil]];
currentLocation.name = paramModel.fromName;发布于 2017-04-21 01:35:12
尝试将标题创建为变量,然后修改该变量上的MKPlacemark字段,如下所示:
MKPlacemark* placemark = [[MKPlacemark alloc]
initWithCoordinate:paramModel.fromCoordinate2D
addressDictionary:nil]];
placemark.title = @"Some Title";
placemark.subtitle = @"Some subtitle";然后将变量设置为映射项构造函数中的参数。
https://stackoverflow.com/questions/43518432
复制相似问题