public static void GetCurrentLocation(TripLog currentLog, bool isStart, NSAction onFound) { if (!CLLocationManager.LocationServicesEnabled) { currentLog.SetLocation(-1, -1, isStart); onFound(); } locationManager = new CLLocationManager(); locationManager.DesiredAccuracy = CLLocation.AccuracyNearestTenMeters; locationDelegate = new MyLocationManagerDelegate(); locationDelegate.OnLocationError += delegate(NSError error) { currentLog.SetLocation(-1, -1, isStart); locationManager.StopUpdatingLocation(); onFound(); }; locationDelegate.OnLocationUpdate += delegate(CLLocation location) { currentLog.SetLocation(location.Coordinate.Latitude, location.Coordinate.Longitude, isStart); locationManager.StopUpdatingLocation(); onFound(); }; locationManager.Delegate = locationDelegate; locationManager.StartUpdatingLocation(); locationDelegate.StartTimer(locationManager); Util.TurnOnNetworkActivity(); }
public override void ViewDidLoad() { base.ViewDidLoad(); // load the appropriate view, based on the device type // initialize our location manager and callback handler iPhoneLocationManager = new CLLocationManager(); double longdute; double latidute; // uncomment this if you want to use the delegate pattern: //locationDelegate = new LocationDelegate (mainScreen); //iPhoneLocationManager.Delegate = locationDelegate; // you can set the update threshold and accuracy if you want: //iPhoneLocationManager.DistanceFilter = 10; // move ten meters before updating //iPhoneLocationManager.HeadingFilter = 3; // move 3 degrees before updating // you can also set the desired accuracy: iPhoneLocationManager.DesiredAccuracy = 1000; // 1000 meters/1 kilometer // you can also use presets, which simply evalute to a double value: //iPhoneLocationManager.DesiredAccuracy = CLLocation.AccuracyNearestTenMeters; // handle the updated location method and update the UI if (UIDevice.CurrentDevice.CheckSystemVersion(6, 0)) { iPhoneLocationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => { UpdateLocation(this, e.Locations [e.Locations.Length - 1]); iPhoneLocationManager.StopUpdatingLocation(); }; } else { // this won't be called on iOS 6 (deprecated) iPhoneLocationManager.UpdatedLocation += (object sender, CLLocationUpdatedEventArgs e) => { UpdateLocation(this, e.NewLocation); iPhoneLocationManager.StopUpdatingLocation(); }; } // handle the updated heading method and update the UI iPhoneLocationManager.UpdatedHeading += (object sender, CLHeadingUpdatedEventArgs e) => { // GPSLocate.LblMagneticHeading.Text = e.NewHeading.MagneticHeading.ToString () + "º"; // GPSLocate.LblTrueHeading.Text = e.NewHeading.TrueHeading.ToString () + "º"; }; // start updating our location, et. al. if (CLLocationManager.LocationServicesEnabled) { iPhoneLocationManager.StartUpdatingLocation(); } if (CLLocationManager.HeadingAvailable) { iPhoneLocationManager.StartUpdatingHeading(); } }
public double getCurrentUserLatitude() { commonLocationManager.DesiredAccuracy = CLLocation.AccuracyBest; if (CLLocationManager.LocationServicesEnabled) { commonLocationManager.StartUpdatingLocation(); } commonLocationManager.StopUpdatingLocation(); return(commonLocationManager.Location.Coordinate.Latitude); }
public override void Failed(CLLocationManager manager, NSError error) { if (error.Code == (int)CLError.Denied) { Console.WriteLine("Access to location services denied"); manager.StopUpdatingLocation(); manager.StopUpdatingLocation(); manager.Delegate = null; } }
public override bool StopTracking() { if (_manager != null && _trackingStarted) { _manager.LocationsUpdated -= HandleLocationsUpdated; _manager.StopUpdatingLocation(); _trackingStarted = false; return(true); } return(false); }
public void RequestLocationServicesAuthorization() { locationManager = new CLLocationManager(); locationManager.Failed += delegate { locationManager.StopUpdatingLocation(); }; locationManager.LocationsUpdated += delegate { locationManager.StopUpdatingLocation(); }; locationManager.AuthorizationChanged += delegate(object sender, CLAuthorizationChangedEventArgs e) { CheckLocationServicesAuthorizationStatus(e.Status); }; locationManager.StartUpdatingLocation(); }
public virtual void LocationsUpdated(CLLocationManager manager, CLLocation[] locations) { if (locations != null && locations.Length != 0) { if (mGotLocation) { return; } Console.WriteLine("Position Status: {0}", locations[0].Timestamp); Console.WriteLine("Position Latitude: {0}", locations[0].Coordinate.Latitude); Console.WriteLine("Position Longitude: {0}", locations[0].Coordinate.Longitude); Console.WriteLine("Horizontal Accuracy : {0}", locations[0].HorizontalAccuracy); Console.WriteLine("Vertical Accuracy : {0}", locations[0].VerticalAccuracy); mGotLocation = true; Mvx.Resolve <ICacheService>().CurrentLat = locations[0].Coordinate.Latitude; Mvx.Resolve <ICacheService>().CurrentLng = locations[0].Coordinate.Longitude; ViewModel.CheckPlacesCommand.Execute(); locationManager.StopUpdatingLocation(); } }
void LocationManager_LocationsUpdated(object sender, CLLocationsUpdatedEventArgs e) { locationManager.StopUpdatingLocation(); var l = e.Locations[0].Coordinate; coder = new CLGeocoder(); coder.ReverseGeocodeLocation(new CLLocation(l.Latitude, l.Longitude), (placemarks, error) => { var city = placemarks[0].Locality; var state = placemarks[0].AdministrativeArea; var weather = new XAMWeatherFetcher(city, state); var result = weather.GetWeather(); InvokeOnMainThread(() => { info.Text = result.Temp + "°F " + result.Text; latLong.Text = l.Latitude + ", " + l.Longitude; cityField.Text = result.City; stateField.Text = result.State; getWeatherButton.Enabled = true; getLocationButton.Enabled = true; }); }); }
public override void Failed(CLLocationManager locationMgr, NSError e) { switch (e.Code) { /* * case (int)CLError.LocationUnknown: * using (var alert = new UIAlertView ("Location Unkown", "Failed to get Location", null, "OK", null)) { * alert.Show (); * } * * break; */ case (int)CLError.Denied: locationMgr.StopUpdatingLocation(); using (var alert = new UIAlertView("Location Unavailable", "Location Service is Turned Off", null, "OK", null)) { alert.Show(); } break; case (int)CLError.Network: using (var alert = new UIAlertView("Network Unavailable", "Network Unreachable", null, "OK", null)) { alert.Show(); } break; } }
public override bool FinishedLaunching (UIApplication app, NSDictionary options) { window = new UIWindow (UIScreen.MainScreen.Bounds); var what = new EntryElement ("What ?", "e.g. pizza", String.Empty); var where = new EntryElement ("Where ?", "here", String.Empty); var section = new Section (); if (CLLocationManager.LocationServicesEnabled) { lm = new CLLocationManager (); lm.LocationsUpdated += delegate (object sender, CLLocationsUpdatedEventArgs e) { lm.StopUpdatingLocation (); here = e.Locations [e.Locations.Length - 1]; var coord = here.Coordinate; where.Value = String.Format ("{0:F4}, {1:F4}", coord.Longitude, coord.Latitude); }; section.Add (new StringElement ("Get Current Location", delegate { lm.StartUpdatingLocation (); })); } section.Add (new StringElement ("Search...", async delegate { await SearchAsync (what.Value, where.Value); })); var root = new RootElement ("MapKit Search Sample") { new Section ("MapKit Search Sample") { what, where }, section }; window.RootViewController = new UINavigationController (new DialogViewController (root, true)); window.MakeKeyAndVisible (); return true; }
/// <summary> /// Stop updating location /// </summary> public void StopLocationUpdates() { if (CLLocationManager.LocationServicesEnabled) { _locMgr.StopUpdatingLocation(); } }
public override bool FinishedLaunching(UIApplication app, NSDictionary options) { global::Xamarin.Forms.Forms.Init(); global::Xamarin.FormsMaps.Init(); locationManager = new CLLocationManager { DesiredAccuracy = CLLocation.AccuracyBest }; locationManager.Failed += (object sender, NSErrorEventArgs e) => { var alert = new UIAlertView(){ Title = "Location manager failed", Message = "The location updater has failed" }; alert.Show(); locationManager.StopUpdatingLocation(); }; locationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => { var newloc = string.Format("{0},{1}", e.Locations[0].Coordinate.Longitude, e.Locations[0].Coordinate.Latitude); App.Self.ChangedClass.BroadcastIt("location", newloc); }; locationManager.StartUpdatingLocation(); LoadApplication(new App()); return base.FinishedLaunching(app, options); }
static Task <PermissionStatus> RequestLocationAsync() { locationManager = new CLLocationManager(); var tcs = new TaskCompletionSource <PermissionStatus>(locationManager); locationManager.AuthorizationChanged += LocationAuthCallback; locationManager.StartUpdatingLocation(); locationManager.StopUpdatingLocation(); return(tcs.Task); void LocationAuthCallback(object sender, CLAuthorizationChangedEventArgs e) { if (e.Status == CLAuthorizationStatus.NotDetermined) { return; } locationManager.AuthorizationChanged -= LocationAuthCallback; tcs.TrySetResult(GetLocationStatus()); locationManager.Dispose(); locationManager = null; } }
public void apagarGPS() { if (locMgr != null) { locMgr.StopUpdatingLocation(); } }
public void GetLocation(Action <GeoLocation> callback) { EventHandler <CLLocationsUpdatedEventArgs> handler = null; handler = (s, e) => { locationManager.StopUpdatingLocation(); var coordinate = e.Locations.First().Coordinate; callback(new GeoLocation() { Latitude = coordinate.Latitude, Longitude = coordinate.Longitude }); locationManager.LocationsUpdated -= handler; }; locationManager.LocationsUpdated += handler; /*locationManager.Failed += (sender, e) => * { * Debug.WriteLine("Failed"); * }; * * locationManager.AuthorizationChanged+= (sender, e) => * { * Debug.WriteLine("Failed"); * };*/ locationManager.StartUpdatingLocation(); }
public override void UpdatedLocation(CLLocationManager manager, CLLocation newLocation, CLLocation oldLocation) { if (newLocation.HorizontalAccuracy <= 100) { manager.StopUpdatingLocation(); StopTimer(); hasLastAttempt = false; Util.TurnOffNetworkActivity(); if (OnLocationUpdate != null) { OnLocationUpdate(newLocation); } return; } if (!hasLastAttempt || newLocation.HorizontalAccuracy <= lastAttempt.HorizontalAccuracy) { hasLastAttempt = true; lastAttempt = newLocation; } }
public LocationPrivacyViewController() { CheckAccess = LocationAccessStatus; RequestAccess = RequestLocationServicesAuthorization; locationManager = new CLLocationManager(); //If previously allowed, start location manager if (CLLocationManager.Status == CLAuthorizationStatus.AuthorizedWhenInUse) { locationManager.StartUpdatingLocation(); } locationManager.Failed += delegate { locationManager.StopUpdatingLocation(); }; locationManager.LocationsUpdated += delegate { var loc = locationManager.Location.ToString(); locationMessage.Text = loc; //MapView MKCoordinateRegion region = new MKCoordinateRegion(locationManager.Location.Coordinate, new MKCoordinateSpan(0.1, 0.1)); mapView.SetRegion(region, true); }; locationManager.AuthorizationChanged += delegate(object sender, CLAuthorizationChangedEventArgs e) { accessStatus.Text = e.Status.ToString(); if (e.Status == CLAuthorizationStatus.AuthorizedWhenInUse) { mapView.ShowsUserLocation = true; locationManager.StartUpdatingLocation(); } }; }
/// <summary> /// Stop listening /// </summary> public Task <bool> StopListeningAsync() { if (!isListening) { return(Task.FromResult(true)); } isListening = false; #if __IOS__ if (CLLocationManager.HeadingAvailable) { manager.StopUpdatingHeading(); } // it looks like deferred location updates can apply to the standard service or significant change service. disallow deferral in either case. if ((listenerSettings?.DeferLocationUpdates ?? false) && CanDeferLocationUpdate) { manager.DisallowDeferredLocationUpdates(); } #endif if (listenerSettings?.ListenForSignificantChanges ?? false) { manager.StopMonitoringSignificantLocationChanges(); } else { manager.StopUpdatingLocation(); } listenerSettings = null; position = null; return(Task.FromResult(true)); }
public Task <GeoLocation> FindAsync() { completion = new TaskCompletionSource <GeoLocation>(); EventHandler <CLLocationsUpdatedEventArgs> handler = null; handler = (sender, e) => { var point = e.Locations.LastOrDefault(); if (point == null) { completion.SetResult(null); } else { completion.SetResult(new GeoLocation { Altitude = point.Altitude, Longitude = point.Coordinate.Longitude, Latitude = point.Coordinate.Latitude }); } location.LocationsUpdated -= handler; location.StopUpdatingLocation(); }; location.LocationsUpdated += handler; location.StartUpdatingLocation(); return(completion.Task); }
public override bool FinishedLaunching(UIApplication app, NSDictionary options) { global::Xamarin.Forms.Forms.Init(); global::Xamarin.FormsMaps.Init(); locationManager = new CLLocationManager { DesiredAccuracy = CLLocation.AccuracyBest }; locationManager.Failed += (object sender, NSErrorEventArgs e) => { var alert = new UIAlertView() { Title = "Location manager failed", Message = "The location updater has failed" }; alert.Show(); locationManager.StopUpdatingLocation(); }; locationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => { var newloc = string.Format("{0},{1}", e.Locations[0].Coordinate.Longitude, e.Locations[0].Coordinate.Latitude); App.Self.ChangedClass.BroadcastIt("location", newloc); }; locationManager.StartUpdatingLocation(); LoadApplication(new App()); return(base.FinishedLaunching(app, options)); }
public override void ViewWillDisappear(bool animated) { base.ViewWillDisappear(animated); if (locationManager != null) { locationManager.StopUpdatingLocation(); } }
private void LocationManager_LocationsUpdated(object sender, CLLocationsUpdatedEventArgs e) { LocationManager.StopUpdatingLocation(); currentPOI.Name = "Exactly here..."; currentPOI.Latitude = e.Locations[0].Coordinate.Latitude; currentPOI.Longitude = e.Locations[0].Coordinate.Longitude; waitEvent.Set(); }
public bool StopLocationStatusWatching() { _locationManager.Delegate = null; _locationManager.StopUpdatingLocation(); _locationManager.Dispose(); _locationManager = null; return(false); }
public void StopLocationUpdates() { locMgr.StopUpdatingLocation(); BaseActivity.locationUpdating = false; BaseActivity.firstLocationAcquired = false; Session.SafeLocationTime = null; context.c.Log("Location updates stopped"); }
// This method should be used to release shared resources and it should store the application state. // If your application supports background exection this method is called instead of WillTerminate // when the user quits. public override void DidEnterBackground(UIApplication application) { if (LocationManager != null) { LocationManager.StopUpdatingLocation(); LocationManager.StartMonitoringSignificantLocationChanges(); } }
void Start() { if (CoreXT.IsDevice) { //eventStore, calender, etc will be null if Init() is not called. Manually initilizing helps save memory and must be done before using. PersonalXT.Init(); manager = new CLLocationManager(); //response for calling PersonalXT.RequestCalendarAccess(); //optional handler if you want to add custom messages to the user PersonalXT.CalendarAccess += delegate(object sender, GrantedEventArgs e) { Log("Calendar grant access: " + e.granted); }; //if reminder is granted access, then add reminder as well as retrieve location data PersonalXT.ReminderAccess += delegate(object sender, GrantedEventArgs e) { Log("Reminder grant access: " + e.granted); if (e.granted) { manager.StartUpdatingLocation(); //will update delagate function manager.DidUpdateLocations } }; //removing reminders after it is found. or you can do whatever else with it. PersonalXT.RemindersFound += delegate(object sender, ReminderArgs e) { foreach (EKReminder obj in e.objList) { PersonalXT.eventStore.RemoveReminder(obj, true, null); } Log("Reminders Removed"); }; //alternate way to do call back functions instead of using delegate file (see example PeoplePickerNavigationControllerDelegate.cs) manager.DidUpdateLocations += delegate(object sender, CLLocationManager.DidUpdateLocationsEventArgs e){ manager.StopUpdatingLocation(); EKStructuredLocation location = new EKStructuredLocation(); location.title = "Current location"; location.geoLocation = e.locations[e.locations.Length - 1] as CLLocation; EKReminder reminder = EKReminder.Reminder(PersonalXT.eventStore); reminder.title = "Buy U3DXT at coordinates: " + location.geoLocation.coordinate; reminder.calendar = PersonalXT.eventStore.defaultCalendarForNewReminders; NSError error = null; PersonalXT.eventStore.SaveReminder(reminder, true, error); if (error != null) { Log("error: " + error); } Log("current location coordinates: " + location.geoLocation.coordinate); }; manager.desiredAccuracy = CLLocation.kCLLocationAccuracyNearestTenMeters; manager.distanceFilter = 1; } }
public async Task <LocationInfo> GetCurrentLocationAsync() { TaskCompletionSource <LocationInfo> tcs = new TaskCompletionSource <LocationInfo>(); EventHandler <CLLocationsUpdatedEventArgs> locationsUpdated = null; try { if (!this.HasLocationPermission) { if (await this.RequestPermissionAsync() != true) { return(null); } } locationsUpdated = (sender, e) => { CLLocation update = e.Locations.FirstOrDefault(); locationManager.LocationsUpdated -= locationsUpdated; locationManager.StopUpdatingLocation(); if (update?.Coordinate != null) { tcs.SetResult(new LocationInfo(update.Coordinate.Latitude, update.Coordinate.Longitude)); } else { tcs.SetException(new NullReferenceException()); } }; locationManager.LocationsUpdated += locationsUpdated; locationManager.StartUpdatingLocation(); } catch (Exception ex) { tcs.SetException(ex); locationManager.LocationsUpdated -= locationsUpdated; locationManager.StopUpdatingLocation(); } await tcs.Task; return(tcs.Task.Result); }
public override void Stop() { if (_isStarted) { _locationManager.StopUpdatingLocation(); _isStarted = false; _locationDelegate.BestPosition = null; } }
private void locationChanged(CLLocation newLoc) { //TODO: this in inefficient allStops = BusDB_GTFS_SQL.Instance.getAllBusStops(newLoc, 2 * METERS_PER_MILE).OrderBy(stop => stop.location, new LocationComparer(newLoc)).ToArray(); closestCalculated = true; myLocation = newLoc; myController.Reload(); locationManger.StopUpdatingLocation(); //only need one }
public void EndLocationUpdates() { started = false; locationManager.StopUpdatingLocation(); if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0)) { locationManager.AllowsBackgroundLocationUpdates = false; } }
/// <summary> /// Stops the location updates. /// </summary> public void StopLocationUpdates() { _mgr.StopUpdatingLocation(); try { _mgr.LocationsUpdated -= _mgr_LocationsUpdated; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } }
/// <summary> /// Stops the listening. /// </summary> private void StopListening() { if (CLLocationManager.HeadingAvailable) { _manager.StopUpdatingHeading(); } _manager.StopUpdatingLocation(); }
public override void Failed (CLLocationManager manager, NSError error) { if (error.Code == (int)CLError.Denied) { Console.WriteLine ("Access to location services denied"); manager.StopUpdatingLocation (); manager.Delegate = null; } }
public override void Failed(CLLocationManager manager, NSError error) { manager.StopUpdatingLocation (); Util.TurnOffNetworkActivity(); StopTimer(); if (OnLocationError != null) { OnLocationError(error); } }
static public void UpdateLocation (CLLocation newLocation, CLLocationManager locManager, GetLocationActions locActions, UITextField textField) { Console.WriteLine(newLocation.Coordinate.Longitude.ToString () + "º"); Console.WriteLine(newLocation.Coordinate.Latitude.ToString () + "º"); //FireEvent OnLocationChanged (textField, locActions, newLocation.Coordinate.Latitude.ToString (), newLocation.Coordinate.Longitude.ToString ()); if (CLLocationManager.LocationServicesEnabled) locManager.StopUpdatingLocation (); if (CLLocationManager.HeadingAvailable) locManager.StopUpdatingHeading (); }
static void Main () { NSApplication.Init (); var locationManager = new CLLocationManager (); locationManager.UpdatedLocation += (sender, args) => { var coord = args.NewLocation.Coordinate; Console.WriteLine ("At {0}", args.NewLocation.Description ()); locationManager.StopUpdatingLocation (); Console.WriteLine (googleUrl, coord.Latitude, coord.Longitude); NSWorkspace.SharedWorkspace.OpenUrl (new Uri (String.Format (googleUrl, coord.Latitude, coord.Longitude))); }; locationManager.StartUpdatingLocation (); NSRunLoop.Current.RunUntil (NSDate.DistantFuture); }
public override void ViewDidAppear(bool animated) { base.ViewDidAppear (animated); locationManager = new CLLocationManager (); locationManager.DesiredAccuracy = CLLocation.AccuracyNearestTenMeters; locationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => { poiData = GeoUtils.GetPoiInformation(e.Locations [e.Locations.Length -1], 20); var js = "World.loadPoisFromJsonData(" + this.poiData.ToString() + ")"; this.arView.CallJavaScript(js); locationManager.StopUpdatingLocation(); locationManager.Delegate = null; }; locationManager.StartUpdatingLocation (); }
public override void ViewDidAppear (bool animated) { base.ViewDidAppear (animated); CLLocationManager locationManager = new CLLocationManager (); locationManager.LocationsUpdated += (sender, e) => { CLLocation location = locationManager.Location; FlurryAgent.SetLocation ( location.Coordinate.Latitude, location.Coordinate.Longitude, (float)location.HorizontalAccuracy, (float)location.VerticalAccuracy); locationManager.StopUpdatingLocation (); Debug.WriteLine ("Logged location."); }; locationManager.StartUpdatingLocation (); }
LocationManager() { locationManager = new CLLocationManager(); locationManager.DesiredAccuracy = CLLocation.AccuracyKilometer; locationManager.LocationsUpdated += (sender, e) => { var loc = e.Locations; if (loc[0] != null) { return; } if (stopped) { return; } _currentLocationAquired = loc[0]; locationManager.StopUpdatingLocation(); stopped = false; }; }
public override void UpdatedLocation (CLLocationManager manager, CLLocation newLocation, CLLocation oldLocation) { attempts++; if (newLocation.Timestamp.SecondsSinceReferenceDate < 10 || attempts >= 3 || newLocation.HorizontalAccuracy < 200f) { //System.Threading.Thread.Sleep(100000); manager.StopUpdatingLocation (); if (callback != null) callback (newLocation); } }
public override void UpdatedLocation(CLLocationManager manager, CLLocation newLocation, CLLocation oldLocation) { manager.StopUpdatingLocation (); locationManager = null; callback (newLocation); }
/// <summary> /// Whenever the GPS sends a new location, update text in label /// and increment the 'count' of updates AND reset the map to that location /// </summary> public override void UpdatedLocation(CLLocationManager manager, CLLocation newLocation, CLLocation oldLocation) { //MKCoordinateSpan span = new MKCoordinateSpan(0.2,0.2); //MKCoordinateRegion region = new MKCoordinateRegion(newLocation.Coordinate,span); //_appd.mylocation = newLocation; //_mapview.SetRegion(region, true); double distanceToConference = MapHelper.Distance (new Coordinate(_appd.ConferenceLocation), new Coordinate(newLocation.Coordinate), UnitsOfLength.Miles); //TODO: Make this Configurable string distanceMessage = "XUnitsFromConference".GetText(); _appd.labelDistance.TextAlignment = UITextAlignment.Center; _appd.labelDistance.Text = String.Format(distanceMessage, Math.Round(distanceToConference,0)); Debug.WriteLine("Distance: {0}", distanceToConference); // only use the first result manager.StopUpdatingLocation(); }
public void RequestLocationServicesAuthorization () { locationManager = new CLLocationManager (); locationManager.Failed += delegate { locationManager.StopUpdatingLocation (); }; locationManager.LocationsUpdated += delegate { locationManager.StopUpdatingLocation (); }; locationManager.AuthorizationChanged += delegate (object sender, CLAuthorizationChangedEventArgs e) { CheckLocationServicesAuthorizationStatus (e.Status); }; locationManager.StartUpdatingLocation (); }
public override void UpdatedLocation(CLLocationManager manager, CLLocation newLocation, CLLocation oldLocation) { Console.WriteLine("Accuracy: " + newLocation.HorizontalAccuracy +", " + newLocation.VerticalAccuracy); _controller.SetInfo(string.Format("Funnet innenfor {0}m/{1}m radius", newLocation.HorizontalAccuracy, newLocation.VerticalAccuracy)); _controller.Latitude = newLocation.Coordinate.Latitude.ToString(); _controller.Longitude = newLocation.Coordinate.Longitude.ToString(); SetLocation(newLocation, "Din posisjon", "Trykk ned og flytt for å endre posisjon."); //Stop updating location if this is close enough... if(newLocation.HorizontalAccuracy <= CLLocation.AccuracyHundredMeters && newLocation.VerticalAccuracy <= CLLocation.AccuracyHundredMeters) { manager.StopUpdatingLocation(); } }
public override void UpdatedLocation(CLLocationManager manager, CLLocation newLocation, CLLocation oldLocation) { _controller.SetInfo(string.Format(Utils.Translate("posiont_found_radius"), newLocation.HorizontalAccuracy, newLocation.VerticalAccuracy)); _controller.Latitude = newLocation.Coordinate.Latitude.ToString(); _controller.Longitude = newLocation.Coordinate.Longitude.ToString(); SetLocation(newLocation, Utils.Translate("yourposition"), Utils.Translate("pin_dragtochange")); //Stop updating location if this is close enough... if(newLocation.HorizontalAccuracy <= CLLocation.AccuracyHundredMeters && newLocation.VerticalAccuracy <= CLLocation.AccuracyHundredMeters) { manager.StopUpdatingLocation(); } }
public override void UpdatedLocation(CLLocationManager manager, CLLocation newLocation, CLLocation oldLocation) { if (screen.CurrentWeather == null) { geocoder = new CLGeocoder (); geocoder.ReverseGeocodeLocation (newLocation, ReverseGeocodeLocationHandle); manager.StopUpdatingHeading(); manager.StopUpdatingLocation(); } }
public override void ViewDidLoad() { base.ViewDidLoad(); map.SetRegion( new MKCoordinateRegion( centerPosition, // 初期位置 new MKCoordinateSpan(0.1d, 0.1d)), true); locMgr = new CLLocationManager(); locMgr.RequestWhenInUseAuthorization(); button.TouchUpInside += (s, _) => { locMgr.DesiredAccuracy = 1000; locMgr.LocationsUpdated += async (object sender, CLLocationsUpdatedEventArgs e) => { var location = e.Locations[e.Locations.Length - 1]; LatitudeText.Text = "Lat: " + location.Coordinate.Latitude.ToString("N6"); LongitudeText.Text = "Lon: " + location.Coordinate.Longitude.ToString("N6"); // PCL で Google Maps API Web サービスに Lat, Lon を投げて住所を取得しています。 var addr = await getAddress.GetJsonAsync(location.Coordinate.Latitude, location.Coordinate.Longitude) ?? "取得できませんでした"; System.Diagnostics.Debug.WriteLine("AddressResult", addr); AddrText.Text = "Address: " + addr; // Map 移動 map.SetRegion( new MKCoordinateRegion( new CLLocationCoordinate2D(location.Coordinate.Latitude, location.Coordinate.Longitude), new MKCoordinateSpan(0.1d, 0.1d)), true); // Pin 追加 map.AddAnnotations(new MKPointAnnotation() { Title = addr, Coordinate = new CLLocationCoordinate2D(location.Coordinate.Latitude, location.Coordinate.Longitude) }); locMgr.StopUpdatingLocation(); }; locMgr.StartUpdatingLocation(); // なぜ下に書くのかあめいさんに聞いてみよう。 }; }
/// <summary> /// Whenever the GPS sends a new location, update text in label /// and increment the 'count' of updates AND reset the map to that location /// </summary> public override void UpdatedLocation(CLLocationManager manager, CLLocation newLocation, CLLocation oldLocation) { double distanceToConference = MapHelper.Distance (new Coordinate(mapVC.ConferenceLocation.Location.To2D()), new Coordinate(newLocation.Coordinate), UnitsOfLength.Miles); mapVC.labelDistance.TextAlignment = UITextAlignment.Center; mapVC.labelDistance.Text = String.Format("{0} miles from MonkeySpace!", Math.Round(distanceToConference,0)); Debug.WriteLine("Distance: {0}", distanceToConference); // only use the first result manager.StopUpdatingLocation(); }
void Start() { if (CoreXT.IsDevice) { //eventStore, calender, etc will be null if Init() is not called. Manually initilizing helps save memory and must be done before using. PersonalXT.Init(); manager = new CLLocationManager(); //response for calling PersonalXT.RequestCalendarAccess(); //optional handler if you want to add custom messages to the user PersonalXT.CalendarAccess += delegate(object sender, GrantedEventArgs e) { Log ("Calendar grant access: " + e.granted); }; //if reminder is granted access, then add reminder as well as retrieve location data PersonalXT.ReminderAccess += delegate(object sender, GrantedEventArgs e) { Log ("Reminder grant access: " + e.granted); if(e.granted){ manager.StartUpdatingLocation(); //will update delagate function manager.DidUpdateLocations } }; //removing reminders after it is found. or you can do whatever else with it. PersonalXT.RemindersFound += delegate(object sender, ReminderArgs e) { foreach(EKReminder obj in e.objList){ PersonalXT.eventStore.RemoveReminder(obj, true, null); } Log("Reminders Removed"); }; //alternate way to do call back functions instead of using delegate file (see example PeoplePickerNavigationControllerDelegate.cs) manager.DidUpdateLocations += delegate(object sender, CLLocationManager.DidUpdateLocationsEventArgs e){ manager.StopUpdatingLocation(); EKStructuredLocation location = new EKStructuredLocation(); location.title = "Current location"; location.geoLocation = e.locations[e.locations.Length-1] as CLLocation; EKReminder reminder = EKReminder.Reminder(PersonalXT.eventStore); reminder.title = "Buy U3DXT at coordinates: " + location.geoLocation.coordinate; reminder.calendar = PersonalXT.eventStore.defaultCalendarForNewReminders; NSError error = null; PersonalXT.eventStore.SaveReminder(reminder,true,error); if(error != null) Log ("error: " + error); Log ("current location coordinates: " + location.geoLocation.coordinate); }; manager.desiredAccuracy = CLLocation.kCLLocationAccuracyNearestTenMeters; manager.distanceFilter = 1; } }
void StartPanToUserLocation () { var locationManager = new CLLocationManager (); locationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => { var coordinate = e.Locations[e.Locations.Length-1].Coordinate; MapView.Camera = new CameraPosition(coordinate, MapViewModel.DEFAULT_ZOOM_LEVEL, 0.0d, 0.0d); locationManager.StopUpdatingLocation(); }; }
public override void ViewDidLoad () { base.ViewDidLoad (); UIButton btnIpConnect = UIButton.FromType (UIButtonType.InfoLight); btnIpConnect.Title (UIControlState.Normal); btnIpConnect.TouchDown += OnIpConnect; this.NavigationItem.RightBarButtonItem = new UIBarButtonItem (btnIpConnect); //this.View.BringSubviewToFront (this.scrollContainer); scrollContainer.ContentSize = new SizeF (this.View.Bounds.Size.Width, this.View.Bounds.Size.Height - 44); _locationManager = new CLLocationManager (); _locationManager.DesiredAccuracy = CLLocation.AccuracyBest; // deprecated in ios 6.0 _locationManager.UpdatedLocation += (object sender, CLLocationUpdatedEventArgs e) => { _userCoords = e.NewLocation.Coordinate; // get the distance from here to Löwenbräukeller var distance = e.NewLocation.DistanceFrom (new CLLocation (LATITUDE_LBK, LONGITUDE_LBK)); string distanceText = Locale.Format("Bis zum Ziel ca: {0}", Util.DistanceToString (distance)); txtDistance.Text = distanceText; if (CLLocationManager.LocationServicesEnabled) { _locationManager.StopUpdatingLocation (); } }; // for ios 6.0 _locationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => { CLLocation recentLocation = e.Locations[e.Locations.Length - 1]; _userCoords = recentLocation.Coordinate; // get the distance from here to Löwenbräukeller var distance = recentLocation.DistanceFrom (new CLLocation (LATITUDE_LBK, LONGITUDE_LBK)); string distanceText = Locale.Format("Bis zum Ziel ca: {0}", Util.DistanceToString (distance)); txtDistance.Text = distanceText; if (CLLocationManager.LocationServicesEnabled) { _locationManager.StopUpdatingLocation (); } }; txtPlan.TextColor = UIColor.White; txtPlan.BackgroundColor = UIColor.Clear; scrollContainer.SetLabelsTextColor (UIColor.White); scrollContainer.SetLabelsBGColor (UIColor.Clear); txtAddress.Text = "Löwenbräukeller Gastronomie GmbH\n" + "Nymphenburgerstrasse 2\n" + "80335 München"; txtPhone.Text = "Tel.: +49 (0)89 - 547 2669-0"; txtFax.Text = "Fax: +49 (0)89 - 547 2669-25"; txtMail.Text = EMAIL; btnPhone.SetImage (UIImage.FromBundle ("image/buttons/phone.png"), UIControlState.Normal); btnPhone.TouchUpInside += delegate { var phoneCaller = new PhoneCaller (); phoneCaller.Call (PHONE_NUMBER); }; btnMail.SetImage (UIImage.FromBundle ("image/buttons/mail.png"), UIControlState.Normal); /* btnMail.TouchDown += delegate { var alert = new UIAlertView (EMAIL, "", null, Locale.GetText ("Cancel"), Locale.GetText ("Mailen")); alert.Clicked += (sender, e) => { if (e.ButtonIndex == 1) { Util.OpenUrl ("mailto:" + EMAIL); } }; alert.Show (); }; */ btnMail.TouchUpInside += (o, e) => { if (MFMailComposeViewController.CanSendMail) { var mail = new MFMailComposeViewController (); mail.SetToRecipients (new string[] { EMAIL}); mail.SetSubject ("Löwenbräu"); mail.SetMessageBody ("", false); mail.Finished += HandleMailFinished; this.PresentViewController (mail, true, null); } }; btnMap.SetImage (UIImage.FromBundle ("image/buttons/map.png"), UIControlState.Normal); btnMap.TouchUpInside += delegate { this.NavigationController.PushViewController (new LbkMapViewController (_lbkCoords, _userCoords), true); }; /* lblImpressum = new UILabel (){ TextColor = UIColor.White, Text ="Impressum", Font = UIFont.BoldSystemFontOfSize (17f), BackgroundColor = UIColor.Clear, //AutoresizingMask = UIViewAutoresizing.FlexibleMargins | UIViewAutoresizing.FlexibleDimensions, }; */ txtPlan.RemoveFromSuperview (); string html = string.Empty; try { using (TextReader textReader = new StreamReader("Data/kontakt.html")) { html = textReader.ReadToEnd (); } } catch { } wvImpressum = new UIWebView (){ BackgroundColor = UIColor.Clear, Opaque = false, DataDetectorTypes = UIDataDetectorType.None, UserInteractionEnabled = false, AutoresizingMask = UIViewAutoresizing.FlexibleDimensions, }; float y = btnMail.Frame.Y + btnMail.Frame.Height + 10; wvImpressum.Frame = new RectangleF (10, y, this.View.Bounds.Width - 20, 580); wvImpressum.LoadHtmlString (html, null); //SetRest (); //this.scrollContainer.Add (lblImpressum); this.scrollContainer.Add (wvImpressum); scrollContainer.ContentSize = new SizeF (this.View.Bounds.Size.Width, y + wvImpressum.Frame.Height); }
public override void ViewDidLoad() { base.ViewDidLoad(); // load the appropriate view, based on the device type // initialize our location manager and callback handler iPhoneLocationManager = new CLLocationManager (); double longdute; double latidute; // uncomment this if you want to use the delegate pattern: //locationDelegate = new LocationDelegate (mainScreen); //iPhoneLocationManager.Delegate = locationDelegate; // you can set the update threshold and accuracy if you want: //iPhoneLocationManager.DistanceFilter = 10; // move ten meters before updating //iPhoneLocationManager.HeadingFilter = 3; // move 3 degrees before updating // you can also set the desired accuracy: iPhoneLocationManager.DesiredAccuracy = 1000; // 1000 meters/1 kilometer // you can also use presets, which simply evalute to a double value: //iPhoneLocationManager.DesiredAccuracy = CLLocation.AccuracyNearestTenMeters; // handle the updated location method and update the UI if (UIDevice.CurrentDevice.CheckSystemVersion (6, 0)) { iPhoneLocationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => { UpdateLocation (this, e.Locations [e.Locations.Length - 1]); iPhoneLocationManager.StopUpdatingLocation(); }; } else { // this won't be called on iOS 6 (deprecated) iPhoneLocationManager.UpdatedLocation += (object sender, CLLocationUpdatedEventArgs e) => { UpdateLocation(this, e.NewLocation); iPhoneLocationManager.StopUpdatingLocation(); }; } // handle the updated heading method and update the UI iPhoneLocationManager.UpdatedHeading += (object sender, CLHeadingUpdatedEventArgs e) => { // GPSLocate.LblMagneticHeading.Text = e.NewHeading.MagneticHeading.ToString () + "º"; // GPSLocate.LblTrueHeading.Text = e.NewHeading.TrueHeading.ToString () + "º"; }; // start updating our location, et. al. if (CLLocationManager.LocationServicesEnabled) iPhoneLocationManager.StartUpdatingLocation (); if (CLLocationManager.HeadingAvailable) iPhoneLocationManager.StartUpdatingHeading (); }
public override void UpdatedLocation(CLLocationManager manager, CLLocation newLocation, CLLocation oldLocation) { if (newLocation.HorizontalAccuracy <= 100) { manager.StopUpdatingLocation (); StopTimer(); hasLastAttempt = false; Util.TurnOffNetworkActivity(); if (OnLocationUpdate != null) { OnLocationUpdate (newLocation); } return; } if (!hasLastAttempt || newLocation.HorizontalAccuracy <= lastAttempt.HorizontalAccuracy) { hasLastAttempt = true; lastAttempt = newLocation; } }