My question is a duplicate of this one: geocoding address into coordinates
with the only difference being that I need to do it in Monotouch (C#) not Objective-C.
I’ve tried this so far with no success:
string sw = searchWhere.Text;
CLGeocoder clg = new CLGeocoder();
clg.GeocodeAddress(sw, HandleCLGeocodeCompletionHandler);
EDIT: The CompletionHandler is called, but I dont know how to get the new Map app to show. (I am very new to iOS dev.)
MKMapView MapIt = new MKMapView();
void HandleCLGeocodeCompletionHandler (CLPlacemark[] placemarks, NSError error)
{
List<ObjAnnotation> oal = new List<ObjAnnotation>();
if ( oal.Count > 0 )
{
MapIt.RemoveAnnotations(oal.ToArray());
}
oal.Clear();
for(int i = 0; i < placemarks.Length; i++)
{
var loc = placemarks[i].Location.Coordinate;
oal.Add(new ObjAnnotation(new CLLocationCoordinate2D(loc.Latitude, loc.Longitude),
placemarks[i].Name, string.Empty));
}
MapIt.AddAnnotationObjects(oal.ToArray());
CustomerDetailTab cdt = CustomerDetailTab;
UIView view = cdt.View;
MapIt.AddSubview (view);
}
The line CustomerDetailTab cdt = CustomerDetailTab; does not build though. I am having trouble understanding how to get the view object.
Got it working thusly: