我正在使用 monotuch 创建一个使用 c# 代码的 iOS 应用程序...我正在尝试通过使用此代码来使用导航/ map 应用程序:
var addressDictionary = new NSMutableDictionary();
addressDictionary.Add(NSObject.FromObject("Name"), NSObject.FromObject(selectedLocation.Name));
MKPlacemark pMark = new MKPlacemark(new CLLocationCoordinate2D (loc.Latitude, loc.Longitude), null);
MKMapItem mapItem = new MKMapItem(pMark);
mapItem.OpenInMaps();
您可以创建一个 NSDictionary 并传递与位置相关的信息 - 如地址、名称等。但是,我不知道如何在 C# 代码中创建和使用字典 - 所有编码示例我发现已经客观化了...
我的整个目标是在 map 应用程序中打开一个位置并传入要在 map 应用程序的地标中显示的位置名称...使用 openinmaps()...
有没有什么方法可以使用 c# 代码创建这个“地址字典”,以便使用 openinmaps 函数将信息传递到 map 应用程序中?
这是一些 objective-c 代码的示例:
-(void)showMap
{
NSDictionary *address = @{
(NSString *)kABPersonAddressStreetKey: _address.text,
(NSString *)kABPersonAddressCityKey: _city.text,
(NSString *)kABPersonAddressStateKey: _state.text,
(NSString *)kABPersonAddressZIPKey: _zip.text
};
MKPlacemark *place = [[MKPlacemark alloc]
initWithCoordinate:_coords
addressDictionary:address];
MKMapItem *mapItem = [[MKMapItem alloc]initWithPlacemark:place];
NSDictionary *options = @{
MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving
};
[mapItem openInMapsWithLaunchOptions:options];
}
请您参考如下方法:
我还没有尝试过这个,但是像这样的东西应该可以工作 - MKPlacemark 使用的 AddressDictionary 与 AddressBook 使用的格式相同
NSMutableDictionary a = new NSMutableDictionary();
a.Add(ABPersonAddressKey.City, new NSString(city));
a.Add(ABPersonAddressKey.State, new NSString(state));
a.Add(ABPersonAddressKey.Zip, new NSString(zip));
a.Add(ABPersonAddressKey.Street, new NSString(addr1));
