public TravelMapLocationDataSource() { locationCheckTimer = new Timer(3000); locationCheckTimer.Elapsed += (object sender, ElapsedEventArgs e) => { Console.WriteLine($"Tick, updating {Locations.Count} items."); foreach (var locale in Locations) { CLGeocoder coder = new CLGeocoder(); CLLocation clLocation = new CLLocation(locale.Location.Latitude, locale.Location.Longitude); locale.LocationNameString = $"{locale.Location.Latitude}, {locale.Location.Longitude}"; coder.ReverseGeocodeLocation(clLocation, (placemarks, error) => { CLPlacemark placemark = placemarks[0]; if (placemark != null) { locale.LocationNameString = placemark.Name; } if (error != null) { Console.WriteLine("Error Placemarking: " + error.LocalizedDescription); locale.LocationNameString = $"{locale.Location.Latitude}, {locale.Location.Longitude}."; } }); RaiseLocationNameAcquired(this, new EventArgs()); } }; locationCheckTimer.Start(); }
public void pegarAsync(float latitude, float longitude, GeoEnderecoEventHandler callback) { var location = new CLLocation(latitude, longitude); var geoCoder = new CLGeocoder(); geoCoder.ReverseGeocodeLocation(location, (placemarkers, error) => { if (placemarkers.Length > 0) { var geoEndereco = placemarkers[0]; var endereco = new GeoEnderecoInfo { Logradouro = geoEndereco.Thoroughfare, Complemento = geoEndereco.SubThoroughfare, Bairro = geoEndereco.SubLocality, Cidade = geoEndereco.Locality, Uf = geoEndereco.AdministrativeArea, CEP = geoEndereco.PostalCode, }; if (callback != null) { ThreadUtils.RunOnUiThread(() => { callback(null, new GeoEnderecoEventArgs(endereco)); }); } } }); }
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 void LocationsUpdated(CLLocationManager manager, CLLocation[] locations) { //throw new System.NotImplementedException(); var currentLocation = locations.ToList().FirstOrDefault(); geocoder.ReverseGeocodeLocation(currentLocation, async(placemarks, error) => { var currentLocationPlacemark = placemarks.ToList().FirstOrDefault(); if (!string.IsNullOrEmpty(currentLocationPlacemark.Country)) { country = currentLocationPlacemark.Country; await PerformPost(); } else { var alert = UIAlertController.Create("Location Error", "We could not retrieve your location. Would you like to use 'Earth' as your location", UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("No", UIAlertActionStyle.Cancel, (alertAction) => { DismissViewController(true, () => { LaunchViewController.ReloadDetails(); }); })); alert.AddAction(UIAlertAction.Create("Yes", UIAlertActionStyle.Default, (alertAction) => { country = "Earth"; })); PresentViewController(alert, true, null); } }); }
void MapView_RegionChanged(object sender, MKMapViewChangeEventArgs e) { var mapView = (MKMapView)sender; _geocoder.ReverseGeocodeLocation(new CLLocation(mapView.CenterCoordinate.Latitude, mapView.CenterCoordinate.Longitude), (placemarks, error) => { if (placemarks.Any()) { var address = ABAddressFormatting.ToString(placemarks[0].AddressDictionary, addCountryName: false); _addressChanged.Invoke(address); } }); }
static Task<IEnumerable<string>> GetAddressesForPositionAsync(Position position) { var location = new CLLocation(position.Latitude, position.Longitude); var geocoder = new CLGeocoder(); var source = new TaskCompletionSource<IEnumerable<string>>(); geocoder.ReverseGeocodeLocation(location, (placemarks, error) => { if (placemarks == null) placemarks = new CLPlacemark[0]; IEnumerable<string> addresses = placemarks.Select(p => ABAddressFormatting.ToString(p.AddressDictionary, false)); source.SetResult(addresses); }); return source.Task; }
public override void ViewDidLoad() { base.ViewDidLoad(); var geocoder = new CLGeocoder(); locationManager = new CLLocationManager(); locationManager.RequestWhenInUseAuthorization(); //locationManager.RequestLocation(); // Only should be called once locationMap.ShowsUserLocation = true; MKCoordinateRegion region; MKCoordinateSpan span; region.Center = locationMap.UserLocation.Coordinate; span.LatitudeDelta = 0.005; span.LongitudeDelta = 0.005; region.Span = span; locationMap.SetRegion(region, true); locationMap.MapType = MKMapType.Standard; var searchResultsController = new chooseLocationResultViewController(locationMap); var searchUpdater = new SearchResultsUpdator(); searchUpdater.UpdateSearchResults += searchResultsController.Search; //add the search controller searchController = new UISearchController(searchResultsController) { SearchResultsUpdater = searchUpdater }; searchController.SearchBar.SizeToFit(); searchController.SearchBar.SearchBarStyle = UISearchBarStyle.Prominent; searchController.SearchBar.Placeholder = "Enter a search query"; searchController.HidesNavigationBarDuringPresentation = false; NavigationItem.TitleView = searchController.SearchBar; DefinesPresentationContext = true; // When the user wants to choose the location manually locationMap.RegionChanged += (sender, e) => { if (setLocation == true) { var coordinate = locationMap.CenterCoordinate; var coor = new CLLocation(coordinate.Latitude, coordinate.Longitude); geocoder.ReverseGeocodeLocation(coor, HandleCLGeocodeCompletionHandler); } }; }
public void GeocodeLastKnownLocation() { var curjob = this.thisManager.thisApp._tabs._jobRunTable.CurrentJob; if (this.thisManager.thisApp._tabs._jobRunTable.FindParentJob(curjob) != null) { curjob = this.thisManager.thisApp._tabs._jobRunTable.FindParentJob(curjob); } var newRequest = new GeoCodingRequestInfo { customer = this.thisManager.thisApp._tabs._jobRunTable.CurrentCustomer.CustomerNumber, job = curjob.JobBookingNumber, timeStamp = DateTime.Now, lat = thisDeviceLat, lng = thisDeviceLng }; RequestQueue.Add(newRequest); if (!geo.Geocoding) { geo.ReverseGeocodeLocation(new CLLocation(newRequest.lat, newRequest.lng), HandleGeocodeCompletion); } }
public override void ViewDidLoad() { base.ViewDidLoad(); mUserTripDataManager = new UserTripDataManager(); mLocationManager = new CLLocationManager(); mLocationManager.DesiredAccuracy = 100; mLocationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => { mCurrentLocationUpdateCounter++; EnableCurrentLocation(); CLLocation location = e.Locations[e.Locations.Length - 1]; mCurrentLocation = e.Locations[e.Locations.Length - 1].Coordinate; mCityString = ""; mStateString = ""; var geocoder = new CLGeocoder(); geocoder.ReverseGeocodeLocation(location, (CLPlacemark[] placemarks, NSError error) => { if ((placemarks != null) && (placemarks.Length > 0)) { mStateString = placemarks[0].AdministrativeArea; mCityString = placemarks[0].Locality; } }); if (mCurrentLocationUpdateCounter > 5) { mLocationManager.StopUpdatingLocation(); } }; txtStartLocation.ShouldReturn += (textField) => { txtEndLocation.BecomeFirstResponder(); return(true); }; txtEndLocation.ShouldReturn += (textField) => { textField.ResignFirstResponder(); return(true); }; setupConnectorView(); txtDate.Text = DateTime.Now.AddMinutes(5).ToString("g"); }
static Task <IEnumerable <string> > GetAddressesForPositionAsync(Position position) { var location = new CLLocation(position.Latitude, position.Longitude); var geocoder = new CLGeocoder(); var source = new TaskCompletionSource <IEnumerable <string> >(); geocoder.ReverseGeocodeLocation(location, (placemarks, error) => { if (placemarks == null) { placemarks = new CLPlacemark[0]; } IEnumerable <string> addresses = placemarks.Select(p => ABAddressFormatting.ToString(p.AddressDictionary, false)); source.SetResult(addresses); }); return(source.Task); }
public static void LoadMapItem(this CLLocation self, MapItemLoadCompletionHandler completionHandler) { var geocoder = new CLGeocoder(); geocoder.ReverseGeocodeLocation(self, (placemarks, error) => { if (placemarks == null) { completionHandler(null, error); return; } if (placemarks.Length == 0) { completionHandler(null, error); return; } var mkPlacement = new MKPlacemark(placemarks[0].Location.Coordinate); completionHandler(new MKMapItem(mkPlacement), null); }); }
public override void ViewDidAppear(bool animated) { base.ViewDidAppear(animated); viewIsDisplayed = true; var region = LocationTriggerCreator.TargetRegion; if (region != null) { var centerLocation = new CLLocation(region.Center.Latitude, region.Center.Longitude); geocoder.ReverseGeocodeLocation(centerLocation, (placemarks, error) => { // The geocoder took too long, we're not on this view any more. if (!viewIsDisplayed) { return; } if (error != null) { DisplayError(error); return; } if (placemarks != null) { var mostLikelyPlacemark = placemarks.FirstOrDefault(); if (mostLikelyPlacemark != null) { CNMutablePostalAddress address = CreatePostalAddress(mostLikelyPlacemark); var addressFormatter = new CNPostalAddressFormatter(); string addressString = addressFormatter.GetStringFromPostalAddress(address); localizedAddress = addressString.Replace("\n", ", "); var section = NSIndexSet.FromIndex(2); TableView.ReloadSections(section, UITableViewRowAnimation.Automatic); } } }); } TableView.ReloadData(); }
public override void LocationsUpdated(CLLocationManager manager, CLLocation[] locations) { var geocoder = new CLGeocoder(); var newLocation = locations[0]; // TODO see if the anonymous function causes a memory leak geocoder.ReverseGeocodeLocation(newLocation, new CLGeocodeCompletionHandler((placemarks, error) => { if (placemarks.Length < 1) { return; } CLPlacemark placemark = placemarks[0]; Location location = new Location(newLocation.Coordinate.Latitude, newLocation.Coordinate.Longitude, placemark.Locality, placemark.SubLocality); CurrentLocation = location; Handler.OnLocationChanged(location); })); }
private UIButton CreateMoreButton(float x, double latitude, double longitude, bool isAlert = false) { var moreButton = new UIButton(UIButtonType.Custom); moreButton.Frame = new RectangleF(x, 4f, 30f, 30f); if (isAlert) { moreButton.SetImage(UIImage.FromBundle("MoreAlert"), UIControlState.Normal); } else { moreButton.SetImage(UIImage.FromBundle("More"), UIControlState.Normal); } moreButton.TouchUpInside += (s, e) => { var alert = AlertControllerHelper.CreateAlertOnMarkerMap(() => { var coordinate = new CLLocationCoordinate2D(latitude, longitude); var mapItem = new MKMapItem(new MKPlacemark(coordinate)); mapItem.OpenInMaps(new MKLaunchOptions() { MapCenter = coordinate }); } , () => { var item = FromObject(SeekiosApp.Helper.StringHelper.GoogleMapLinkShare(latitude, longitude)); var activityItems = new NSObject[] { item }; UIActivity[] applicationActivities = null; var activityController = new UIActivityViewController(activityItems, applicationActivities); if (_mapViewcontroller != null) { _mapViewcontroller.PresentViewController(activityController, true, null); } else if (_mapHistoriccontroller != null) { _mapHistoriccontroller.PresentViewController(activityController, true, null); } else if (_mapAllSeekios != null) { _mapAllSeekios.PresentViewController(activityController, true, null); } else if (_modeZonecontroller != null) { _modeZonecontroller.PresentViewController(activityController, true, null); } } , () => { var geoCode2 = new CLGeocoder(); geoCode2.ReverseGeocodeLocation(new CLLocation(latitude, longitude), (placemarks, error) => { if (placemarks?.Count() > 0) { UIPasteboard.General.String = FormatSeekiosAdress(placemarks.Last()); } else { var alert2 = AlertControllerHelper.CreateAlertOnMarkerMapNoAdress(); if (_mapViewcontroller != null) { _mapViewcontroller.PresentViewController(alert2, true, null); } else if (_mapHistoriccontroller != null) { _mapHistoriccontroller.PresentViewController(alert2, true, null); } else if (_mapAllSeekios != null) { _mapAllSeekios.PresentViewController(alert2, true, null); } else if (_modeZonecontroller != null) { _modeZonecontroller.PresentViewController(alert2, true, null); } } }); }); var geoCode = new CLGeocoder(); geoCode.ReverseGeocodeLocation(new CLLocation(latitude, longitude), (placemarks, error) => { if (placemarks?.Count() > 0) { alert.Title = FormatSeekiosAdress(placemarks.Last()); } else { alert.Title = Application.LocalizedString("NoAdressSeekios"); } }); if (_mapViewcontroller != null) { _mapViewcontroller.PresentViewController(alert, true, null); } else if (_mapHistoriccontroller != null) { _mapHistoriccontroller.PresentViewController(alert, true, null); } else if (_mapAllSeekios != null) { _mapAllSeekios.PresentViewController(alert, true, null); } else if (_modeZonecontroller != null) { _modeZonecontroller.PresentViewController(alert, true, null); } }; return(moreButton); }
private void OnGUI() { KitchenSink.OnGUIBack(); GUILayout.BeginArea(new Rect(50, 50, Screen.width - 100, Screen.height / 2 - 50)); //this is the original way of how objective C use call back functions: Delegates using separate files. //in this case the file is PeoplePickerNavigationControllerDelegate.cs //we have have it easier to use delegates instead of creating new files for each delegate. //see examples above. Ex: PersonalXT.CalendarAccess += delegate( .... if (GUILayout.Button("pick/select from contacts", GUILayout.ExpandHeight(true))) { ABPeoplePickerNavigationController picker = new ABPeoplePickerNavigationController(); if (pickerDelegate == null) pickerDelegate = new PeoplePickerNavigationControllerDelegate(); picker.peoplePickerDelegate = pickerDelegate; UIApplication.deviceRootViewController.PresentViewController(picker, true, null); } if (GUILayout.Button("get all contacts", GUILayout.ExpandHeight(true))) { //this will get you the contact records in which you can manipulate, etc //ABRecord[] contacts = PersonalXT.GetAllContactRecords(); //convienent function to get the names of the contacts string[] contactList = PersonalXT.GetAllContactNames(); for(int i=0; i < contactList.Length; i++){ Log("Contact " + i + ": " + contactList[i]); } } if (GUILayout.Button("add new contacts", GUILayout.ExpandHeight(true))) { addNewContact(); } if (GUILayout.Button("init Calendar and show events within 30 days", GUILayout.ExpandHeight(true))) { checkEventStoreAccessForCalendar(); } if (GUILayout.Button("add an event for tomorrow", GUILayout.ExpandHeight(true))) { addEventForTomorrow(); } if (GUILayout.Button("add alarm to events", GUILayout.ExpandHeight(true))) { createAlarmForEvents(); } if (GUILayout.Button("add reminder with geolocation of current location", GUILayout.ExpandHeight(true))) { PersonalXT.RequestReminderAccess(); } if (GUILayout.Button("reverse geocode happiest place on earth", GUILayout.ExpandHeight(true))) { CLLocation location = new CLLocation(33.809, -117.919); CLGeocoder geocoder = new CLGeocoder(); geocoder.ReverseGeocodeLocation(location, delegate(object[] placemarks, NSError error) { if (error != null) Debug.Log(error.LocalizedDescription()); else { foreach (var p in placemarks) { var placemark = p as CLPlacemark; Debug.Log("placemark: " + placemark.name + "\n" + ABAddressFormatting.ABCreateString(placemark.addressDictionary, true)); } } }); } if (GUILayout.Button("Significant location change", GUILayout.ExpandHeight(true))) { if (!CLLocationManager.LocationServicesEnabled() || !CLLocationManager.SignificantLocationChangeMonitoringAvailable()) { Debug.Log("Significant change monitoring not available."); } else { // CLLocationManager manager = new CLLocationManager(); manager.StartMonitoringSignificantLocationChanges(); } } //commented out remove all events and reminders so users don't accidentally remove important events /* if (GUILayout.Button("remove all Events", GUILayout.ExpandHeight(true))) { PersonalXT.RemoveAllEvents(); Log ("Removed events"); } if (GUILayout.Button("remove all Reminders", GUILayout.ExpandHeight(true))) { PersonalXT.GetAllReminders(); //you can get all the reminders and handle them in line 59 above //PersonalXT.RemoveAllReminders(); //or you can simply call removeAllReminders }*/ GUILayout.EndArea(); OnGUILog(); }
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(); } }
private void OnGUI() { KitchenSink.OnGUIBack(); GUILayout.BeginArea(new Rect(50, 50, Screen.width - 100, Screen.height / 2 - 50)); //this is the original way of how objective C use call back functions: Delegates using separate files. //in this case the file is PeoplePickerNavigationControllerDelegate.cs //we have have it easier to use delegates instead of creating new files for each delegate. //see examples above. Ex: PersonalXT.CalendarAccess += delegate( .... if (GUILayout.Button("pick/select from contacts", GUILayout.ExpandHeight(true))) { ABPeoplePickerNavigationController picker = new ABPeoplePickerNavigationController(); if (pickerDelegate == null) { pickerDelegate = new PeoplePickerNavigationControllerDelegate(); } picker.peoplePickerDelegate = pickerDelegate; UIApplication.deviceRootViewController.PresentViewController(picker, true, null); } if (GUILayout.Button("get all contacts", GUILayout.ExpandHeight(true))) { Log("Address book authorization status: " + ABAddressBook.GetAuthorizationStatus()); var addressBook = ABAddressBook.Create(null, null); addressBook.RequestAccess(delegate(bool granted, NSError error) { Log("Granted: " + granted); //convienent function to get the names of the contacts string[] contactList = PersonalXT.GetAllContactNames(); for (int i = 0; i < contactList.Length; i++) { Log("Contact " + i + ": " + contactList[i]); } }); } if (GUILayout.Button("add new contacts", GUILayout.ExpandHeight(true))) { addNewContact(); } if (GUILayout.Button("init Calendar and show events within 30 days", GUILayout.ExpandHeight(true))) { checkEventStoreAccessForCalendar(); } if (GUILayout.Button("add an event for tomorrow", GUILayout.ExpandHeight(true))) { addEventForTomorrow(); } if (GUILayout.Button("add alarm to events", GUILayout.ExpandHeight(true))) { createAlarmForEvents(); } if (GUILayout.Button("add reminder with geolocation of current location", GUILayout.ExpandHeight(true))) { PersonalXT.RequestReminderAccess(); } if (GUILayout.Button("reverse geocode happiest place on earth", GUILayout.ExpandHeight(true))) { CLLocation location = new CLLocation(33.809, -117.919); CLGeocoder geocoder = new CLGeocoder(); geocoder.ReverseGeocodeLocation(location, delegate(object[] placemarks, NSError error) { if (error != null) { Debug.Log(error.LocalizedDescription()); } else { foreach (var p in placemarks) { var placemark = p as CLPlacemark; Debug.Log("placemark: " + placemark.name + "\n" + ABAddressFormatting.ABCreateString(placemark.addressDictionary, true)); } } }); } if (GUILayout.Button("Significant location change", GUILayout.ExpandHeight(true))) { if (!CLLocationManager.LocationServicesEnabled() || !CLLocationManager.SignificantLocationChangeMonitoringAvailable()) { Debug.Log("Significant change monitoring not available."); } else { // CLLocationManager manager = new CLLocationManager(); manager.StartMonitoringSignificantLocationChanges(); } } //commented out remove all events and reminders so users don't accidentally remove important events /* * if (GUILayout.Button("remove all Events", GUILayout.ExpandHeight(true))) { * PersonalXT.RemoveAllEvents(); * Log ("Removed events"); * } * * if (GUILayout.Button("remove all Reminders", GUILayout.ExpandHeight(true))) { * PersonalXT.GetAllReminders(); //you can get all the reminders and handle them in line 59 above * //PersonalXT.RemoveAllReminders(); //or you can simply call removeAllReminders * }*/ GUILayout.EndArea(); OnGUILog(); }