public override void ViewDidLoad() { base.ViewDidLoad(); ResultLabel = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Lines = 0 }; View.AddSubview(ResultLabel); View.AddConstraint(NSLayoutConstraint.Create(ResultLabel, NSLayoutAttribute.Left, NSLayoutRelation.Equal, View, NSLayoutAttribute.Left, 1f, 0f)); View.AddConstraint(NSLayoutConstraint.Create(ResultLabel, NSLayoutAttribute.Right, NSLayoutRelation.Equal, View, NSLayoutAttribute.Right, 1f, 0f)); View.AddConstraint(NSLayoutConstraint.Create(ResultLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, View, NSLayoutAttribute.TopMargin, 1f, 0f)); View.AddConstraint(NSLayoutConstraint.Create(ResultLabel, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, View, NSLayoutAttribute.BottomMargin, 1f, 0f)); GoButton = new UIButton() { TranslatesAutoresizingMaskIntoConstraints = false, BackgroundColor = UIColor.LightGray }; GoButton.SetTitle("Go", UIControlState.Normal); View.AddSubview(GoButton); View.AddConstraint(NSLayoutConstraint.Create(GoButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, View, NSLayoutAttribute.Left, 1f, 0f)); View.AddConstraint(NSLayoutConstraint.Create(GoButton, NSLayoutAttribute.Right, NSLayoutRelation.Equal, View, NSLayoutAttribute.Right, 1f, 0f)); View.AddConstraint(NSLayoutConstraint.Create(GoButton, NSLayoutAttribute.Top, NSLayoutRelation.GreaterThanOrEqual, View, NSLayoutAttribute.TopMargin, 1f, 0f)); View.AddConstraint(NSLayoutConstraint.Create(GoButton, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, View, NSLayoutAttribute.BottomMargin, 1f, 0f)); GoButton.TouchUpInside += GoButton_TouchUpInside; // We can start buffer the location before user click get location. // This enabled the location to retrieve faster but it will ignore any error such as lack of permission. Geolocator = new Geolocator(); Geolocator.StartCacheLocation(); }
public MainPage() { InitializeComponent(); // We can start buffer the location before user click get location. // This enabled the location to retrieve faster but it will ignore any error such as lack of permission. Geolocator = new Geolocator(); Geolocator.StartCacheLocation(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_main); Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); ResultTextView = FindViewById <TextView>(Resource.Id.result_text_view); ClearCacheLocationButton = FindViewById <Button>(Resource.Id.clear_cache_location_button); ClearCacheLocationButton.Click += ClearCacheLocationButtonOnClick; GetLocationForegroundButton = FindViewById <Button>(Resource.Id.get_location_foreground_button); GetLocationForegroundButton.Click += GetLocationForegroundButtonOnClick; GetLocationBackgroundButton = FindViewById <Button>(Resource.Id.get_location_background_button); GetLocationBackgroundButton.Click += GetLocationBackgroundButtonOnClick; // We can start buffer the location before user click get location. // This enabled the location to retrieve faster but it will ignore any error such as lack of permission. Geolocator = new Geolocator(); Geolocator.StartCacheLocation(); }