Question

I am using monotouch to create an iOS application using c# code...I'm trying to use the navigation/maps application by using this code:

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

You are able to create an NSDictionary and pass in information pertaining to the location - like the address, name, etc. However, I don't know how to create and use the dictionary in the c# code - all the coding examples I have found have been objective c...

My whole goal is to open a location in the maps app and pass in the name of a location to be displayed in the placemark in the maps application...using openinmaps()...

Is there any way to create this "address dictionary" using the c# code so that the info is passed into the maps application using the openinmaps function?

Here is an example of some objective c code:

-(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];
}
Was it helpful?

Solution

I haven't tried this, but something like this should work - the AddressDictionary used by MKPlacemark is the same format as used by 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));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top