private void OnAddBookmarksButtonClicked(object sender, EventArgs e)
{
//Create Alert for bookmark name
var textInputAlertController = UIAlertController.Create("Provide the bookmark name",
string.Empty, UIAlertControllerStyle.Alert);
//Add Text Input
textInputAlertController.AddTextField(textField => { });
//Add Actions
var cancelAction = UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null);
var okayAction = UIAlertAction.Create("Done", UIAlertActionStyle.Default, alertAction =>{
// Get the name from the text field
var name = textInputAlertController.TextFields[0].Text;
// Exit if the name is empty
if (string.IsNullOrEmpty(name))
return;
// Check to see if there is a bookmark with same name
bool doesNameExist = _myMapView.Map.Bookmarks.Any(b => b.Name == name);
if (doesNameExist)
return;
// Create a new bookmark
Bookmark myBookmark = new Bookmark();
myBookmark.Name = name;
// Get the current viewpoint from map and assign it to bookmark
myBookmark.Viewpoint = _myMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry);
// Add the bookmark to bookmark collection of the map
_myMapView.Map.Bookmarks.Add(myBookmark);
});
textInputAlertController.AddAction(cancelAction);
textInputAlertController.AddAction(okayAction);
//Present Alert
PresentViewController(textInputAlertController, true, null);
}