2013-05-28 45 views
1

我使用MonoTouch的使用C#代码来创建iPhone应用程序......我试图通过使用此代码来使用导航/地图应用:的iOS地图的MonoTouch

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#代码中创建和使用字典 - 我发现所有编码示例都是客观的c。 ..

我的整个目标是在地图应用程序中打开一个位置,并传递地图名称以显示在地图应用程序的地标中...使用openinmaps ()...

有没有什么办法使用c#代码创建这个“地址词典”,以便使用openinmaps函数将信息传递到地图应用程序中?

下面是一些客观的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]; 
} 

回答

4

我没有尝试这样做,但这样的事情应该工作 - 通过MKPlacemark使用的AddressDictionary是相同的格式,使用通讯簿

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));