зеркало из https://github.com/xamarin/ios-samples.git
Code cleanup in MapKitSearch
This commit is contained in:
Родитель
31a258e9fd
Коммит
a98c0b6caa
|
@ -38,9 +38,6 @@ namespace MapKitSearch {
|
|||
lm.StartUpdatingLocation ();
|
||||
}));
|
||||
}
|
||||
// section.Add (new StringElement ("Search...", delegate {
|
||||
// Search (what.Value, where.Value);
|
||||
// }));
|
||||
|
||||
section.Add (new StringElement ("Search...", async delegate {
|
||||
await SearchAsync (what.Value, where.Value);
|
||||
|
@ -68,38 +65,6 @@ namespace MapKitSearch {
|
|||
return new CLLocationCoordinate2D ();
|
||||
}
|
||||
|
||||
void Search (string what, string where)
|
||||
{
|
||||
var coord = here == null ? Parse (where) : here.Coordinate;
|
||||
|
||||
MKCoordinateSpan span = new MKCoordinateSpan (0.25, 0.25);
|
||||
MKLocalSearchRequest request = new MKLocalSearchRequest ();
|
||||
request.Region = new MKCoordinateRegion (coord, span);
|
||||
request.NaturalLanguageQuery = what;
|
||||
|
||||
MKLocalSearch search = new MKLocalSearch (request);
|
||||
|
||||
search.Start (delegate (MKLocalSearchResponse response, NSError error) {
|
||||
// this is executed in the application main thread
|
||||
if (response == null || error != null)
|
||||
return;
|
||||
|
||||
var section = new Section ("Search Results for " + what);
|
||||
results.Clear ();
|
||||
foreach (MKMapItem mi in response.MapItems) {
|
||||
results.Add (mi);
|
||||
var element = new StyledStringElement (mi.Name, mi.PhoneNumber, UITableViewCellStyle.Subtitle);
|
||||
element.Accessory = UITableViewCellAccessory.DisclosureIndicator;
|
||||
element.Tapped += () => { results [element.IndexPath.Row].OpenInMaps (); };
|
||||
section.Add (element);
|
||||
}
|
||||
|
||||
var root = new RootElement ("MapKit Search Sample") { section };
|
||||
var dvc = new DialogViewController (root);
|
||||
(window.RootViewController as UINavigationController).PushViewController (dvc, true);
|
||||
});
|
||||
}
|
||||
|
||||
async Task SearchAsync (string what, string where)
|
||||
{
|
||||
var coord = here == null ? Parse (where) : here.Coordinate;
|
||||
|
|
Загрузка…
Ссылка в новой задаче