laktak
laktak

Reputation: 60043

MonoTouch MKLocalSearch Example

I couldn't find a sample for MKLocalSearch so I've added one below.

Upvotes: 1

Views: 534

Answers (2)

poupou
poupou

Reputation: 43553

Support for iOS 6.1 is available in MonoTouch 6.0.10 (released last night, same day as iOS 6.1).

As stated in the release notes (see previous link) a new sample was added to show the new MapKit search features. It's available in the Xamarin's monotouch-samples at github.

Upvotes: 1

laktak
laktak

Reputation: 60043

MKLocalSearchRequest req=new MKLocalSearchRequest
{
  Region=new MKCoordinateRegion(map.CenterCoordinate, new MKCoordinateSpan(0.05, 0.05)), // ~50km radius
  NaturalLanguageQuery=text,
};

var localSearch=new MKLocalSearch(req);
localSearch.Start(delegate(MKLocalSearchResponse response, NSError error)
{
  if (error==null)
  {
    foreach (var item in response.MapItems)
    {
      var coord=item.IsCurrentLocation?map.UserLocation.Coordinate:item.Placemark.Coordinate;
      map.AddAnnotation(new MKPointAnnotation { Coordinate=coord, Title=item.Name });
    }
  }
  //else show error
});

map is your MKMapView, text is the location/business you want to search for.

Upvotes: 2

Related Questions