public async void OnLocationChanged(Location location) { _currentLocation = location; if (_currentLocation == null) { state.Text = "Location is not available"; } else { Log.Debug (TAG, string.Format ("{0:f6},{1:f6}", _currentLocation.Latitude, _currentLocation.Longitude)); //Please use Emulator API23. Geocoder is not available on Emulator API19, got bug address = await ReverseGeocodeCurrentLocation (); if (address == null) { state.Text = "String: No Address"; } else { state.Text = address.GetAddressLine (address.MaxAddressLineIndex - 1); int complete = await ccm.HTMLDownload (address.GetAddressLine (address.MaxAddressLineIndex - 1)); if (complete == 1) { int locationIndex = GetNearestLocationIndex (); UpdateUI (locationIndex); } else { UpdateUI (999); } } } }
public override ICursor Query(Android.Net.Uri uri, string[] projection, string selection, string[] selectionArgs, string sortOrder) { var query = uri.LastPathSegment.ToLowerInvariant (); IList<Address> addresses = null; try { addresses = geocoder.GetFromLocationName (query, SuggestionCount, LowerLeftLat, LowerLeftLon, UpperRightLat, UpperRightLon); } catch (Exception e) { AnalyticsHelper.LogException ("SuggestionsFetcher", e); Android.Util.Log.Warn ("SuggestionsFetcher", e.ToString ()); addresses = new Address[0]; } var cursor = new MatrixCursor (new string[] { BaseColumns.Id, SearchManager.SuggestColumnText1, SearchManager.SuggestColumnText2, SearchManager.SuggestColumnIntentExtraData }, addresses.Count); long id = 0; foreach (var address in addresses) { int dummy; if (int.TryParse (address.Thoroughfare, out dummy)) continue; var options1 = new string[] { address.FeatureName, address.Thoroughfare }; var options2 = new string[] { address.Locality, address.AdminArea }; var line1 = string.Join (", ", options1.Where (s => !string.IsNullOrEmpty (s)).Distinct ()); var line2 = string.Join (", ", options2.Where (s => !string.IsNullOrEmpty (s))); if (string.IsNullOrEmpty (line1) || string.IsNullOrEmpty (line2)) continue; cursor.AddRow (new Java.Lang.Object[] { id++, line1, line2, address.Latitude.ToSafeString () + "|" + address.Longitude.ToSafeString () }); } return cursor; }
public LatLng getLatLngFromName(string name) { //This Method takes a Location name as an argument and returns the LatLng Object of the Location LatLng geoPoint; Geocoder geocoder = new Geocoder(this); IList <Android.Locations.Address> list = geocoder.GetFromLocationName(name, 5); Android.Locations.Address address = list[0]; geoPoint = new LatLng(address.Latitude, address.Longitude); return(geoPoint); }
private static Address Convert(Android.Locations.Address address) { string addressLine = address.GetAddressLine(0); return(new Address { Latitude = address.Latitude, Longitude = address.Longitude, Name = address.FeatureName, Country = address.CountryName, PostalCode = address.PostalCode, Locality = address.Locality, SubLocality = address.SubLocality, Thoroughfare = address.Thoroughfare, SubThoroughfare = address.SubThoroughfare, AdministrativeArea = address.AdminArea, SubAdministrativeArea = address.SubAdminArea, AddressLine = addressLine, }); }
void SetWorkMarker(Android.Locations.Address addr) { LatLng searchLocation; if (addr != null) { searchLocation = new LatLng( Convert.ToDouble(addr.Latitude, (CultureInfo.InvariantCulture)), Convert.ToDouble(addr.Longitude, (CultureInfo.InvariantCulture))); } else { searchLocation = new LatLng( Convert.ToDouble(CompanyLat, CultureInfo.InvariantCulture), Convert.ToDouble(CompanyLng, CultureInfo.InvariantCulture)); } CameraPosition.Builder builderSearch = CameraPosition.InvokeBuilder(); builderSearch.Target(searchLocation); builderSearch.Zoom(_zoom); CameraPosition searchCameraPosition = builderSearch.Build(); _cameraUpdate = CameraUpdateFactory.NewCameraPosition(searchCameraPosition); _map.MoveCamera(_cameraUpdate); _workDescriptor = BitmapDescriptorFactory.FromResource(Resource.Drawable.add_loc_marker); if (_workMarker != null) { _workMarker.Remove(); } MarkerOptions markerOptions = new MarkerOptions(); markerOptions.SetPosition(searchLocation); markerOptions.SetIcon(_workDescriptor); _workMarker = _map.AddMarker(markerOptions); //work_marker.Title = GetString(Resource.String.work_location); _latTemporary = searchLocation.Latitude.ToString(); _lngTemporary = searchLocation.Longitude.ToString(); }
private void SaveAddress(Address address) { if (address != null) { string deviceAddress = ""; for (int i = 0; i < address.MaxAddressLineIndex; i++) { deviceAddress += address.GetAddressLine(i) + ", "; } deviceAddress = deviceAddress.Trim(); deviceAddress = deviceAddress.TrimEnd(','); _addressText = deviceAddress; var crashLocationResult = new CrashLocationResult { Address = new DTO.Location { HouseNameOrNumber = address.FeatureName, Country = address.CountryName, PostCode = address.PostalCode, Town = address.Locality, StreetName = address.Thoroughfare }, Lat = _currentLocation.Latitude, Lng = _currentLocation.Longitude, AddressAsString = _addressText }; MessagingCenter.Send<IGetLocation, CrashLocationResult>(this, "addressExists", crashLocationResult); } else { _addressText = ""; } //push the data to the message centre!!! }
void DisplayAddress(Address address) { var label = ((WalkAround.MainContent)WalkAround.App.Current.MainPage).AddressLabel; if (address != null) { StringBuilder deviceAddress = new StringBuilder(); for (int i = 0; i < address.MaxAddressLineIndex; i++) { deviceAddress.AppendLine(address.GetAddressLine(i)); } // Remove the last comma from the end of the address. label.Text = deviceAddress.ToString(); } else { label.Text = "Unable to determine the address. Try again in a few minutes."; } }
void DisplayAddress (Address address) { if (address != null) { StringBuilder deviceAddress = new StringBuilder (); for (int i = 0; i < address.MaxAddressLineIndex; i++) { deviceAddress.AppendLine (address.GetAddressLine (i)); } // Remove the last comma from the end of the address. _addressText.Text = deviceAddress.ToString (); } else { Insights.Track ("UnableToDetermineAddress"); _addressText.Text = "Unable to determine the address. Try again in a few minutes."; } }
string FormatAddress(Address addr) { StringBuilder addressText = new StringBuilder(); addressText.Append(addr.SubThoroughfare); addressText.AppendFormat(" {0}", addr.Thoroughfare); addressText.AppendFormat(", {0}", addr.Locality); addressText.AppendFormat(", {0}", addr.CountryCode); addressText.AppendLine(); addressText.AppendLine(); return addressText.ToString(); }
public async void OnLocationChanged(Location location) { _currentLocation = location; sec++; if (_currentLocation != null) { Log.Debug (TAG, string.Format ("{0:f6},{1:f6}", _currentLocation.Latitude, _currentLocation.Longitude)); address = await ReverseGeocodeCurrentLocation(); int complete = 0; if (address != null) { string state = address.GetAddressLine (address.MaxAddressLineIndex - 1); while (complete != 1) { complete = await ccm.HTMLDownload (state); } if (complete == 1) { int locationIndex = GetNearestLocationIndex (); string currentRegion = regionEntry [locationIndex].ToString (); string APIString = latestAPI [locationIndex].ToString (); string currentAPI = APIString.Remove (APIString.Length - 1); string currentLegend = string.Empty; char legends = APIString [APIString.Length - 1]; if (legends == '*') { currentLegend = "PM10"; } else if (legends == 'a') { currentLegend = "SO2"; } else if (legends == 'b') { currentLegend = "NO2"; } else if (legends == 'c') { currentLegend = "Ozone"; } else if (legends == 'd') { currentLegend = "CO"; } else if (legends == '&') { currentLegend = "Multiple"; } else { currentLegend = "Unknown"; } notiTitle = "Malaysia API"; notiContent = String.Format ("API: {0}\nHighest Concentration: {1}", currentAPI, currentLegend); notiMinContent = String.Format ("API: {0}", APIString); } else { notiTitle = "Malaysia API"; notiContent = String.Format ("Can't get HTMLCompletion"); notiMinContent = String.Format ("Can't get HTMLCompletion"); } } else { notiTitle = "Malaysia API"; notiContent = String.Format ("Can't get address"); notiMinContent = String.Format ("Can't get address"); } } else { notiTitle = "Malaysia API"; notiContent = String.Format ("Can't get location"); notiMinContent = String.Format ("Can't get HTMLCompletion"); } SendNotification (notiTitle, notiContent, notiMinContent); }
private static string ConvertToString(Android.Locations.Address address) { return(address.GetAddressLine(0) + ", " + address.Locality); }
protected void UpdateAddressFields(Address addr) { if (String.IsNullOrEmpty(_nameEditText.Text)) _nameEditText.Text = addr.FeatureName; if (String.IsNullOrEmpty(_addrEditText.Text)) { for (int i = 0; i < addr.MaxAddressLineIndex; i++) { if (!String.IsNullOrEmpty(_addrEditText.Text)) _addrEditText.Text += System.Environment.NewLine; _addrEditText.Text += addr.GetAddressLine(i); } } }
private void DisplayAddress(Address alamat) { if (alamat != null) { var deviceAddress = new StringBuilder(); for (var i = 0; i < alamat.MaxAddressLineIndex; i++) { deviceAddress.AppendLine(alamat.GetAddressLine(i)); } _alamatText.Text = deviceAddress.ToString(); } else { _alamatText.Text = "Selamat! Kamu nyasar."; } }
// ILocationListener is a way for the Service to subscribe for updates // from the System location Service public void OnLocationChanged(Android.Locations.Location location) { try { if (DependencyService.Get <ICredentialsService>().DoCredentialsExist()) { //LocationChanged(this, new LocationChangedEventArgs(location)); // This should be updating every time we request new location updates // both when teh app is in the background, and in the foreground Log.Debug(logTag, $"Latitude is {location.Latitude}"); Log.Debug(logTag, $"Longitude is {location.Longitude}"); Log.Debug(logTag, $"Altitude is {location.Altitude}"); Log.Debug(logTag, $"Speed is {location.Speed}"); Log.Debug(logTag, $"Accuracy is {location.Accuracy}"); Log.Debug(logTag, $"Bearing is {location.Bearing}"); Transporte viajeActivo = null; Util util = new Util(); bool?tercero = null; if (util.UsuarioTienePermiso("eventoslogisticosterceros")) { tercero = true; } EventoLogisticoBLL eventoBLL = new EventoLogisticoBLL(); List <Transporte> transportesHabilitadosRegistroEventos = new List <Transporte>(); Task.Run(async() => { transportesHabilitadosRegistroEventos = await eventoBLL.SeleccionarTransporteHabilitadoRegistroEventos(!await ParametrosSistema.isOnline, tercero); if (transportesHabilitadosRegistroEventos != null && transportesHabilitadosRegistroEventos.Count > 0) { viajeActivo = transportesHabilitadosRegistroEventos[0]; } if (viajeActivo != null) { //The Geocoder class retrieves a list of address from Google over the internet Geocoder geocoder = new Geocoder(Android.App.Application.Context); IList <Android.Locations.Address> addressList = null; Android.Locations.Address address = null; double lat = 0; double lon = 0; string _address = string.Empty; try { if (location.Latitude != 0) { addressList = geocoder.GetFromLocation(location.Latitude, location.Longitude, 1); address = addressList.FirstOrDefault(); _address = address.SubThoroughfare + " " + address.Thoroughfare + ", " + address.Locality + ", " + address.AdminArea + ", " + address.CountryCode; //_address = address. } lat = location.Latitude; lon = location.Longitude; } catch (Exception ex) { } //Se crea evento logistico para guardar la posicion del gps EventoLogistico evento = new EventoLogistico(); //Cero es solo reportar posicion evento.IdTipoEvento = 44; //Evento reportar posicion evento.Placa = viajeActivo.Placa; evento.NumeroManifiesto = viajeActivo.NumeroTransporte; evento.Latitud = (float)lat; evento.Longitud = (float)lon; evento.DescripcionPosicion = _address; evento.FechaEvento = DateTime.Now; evento.NumeroDocumentoConductor = viajeActivo.NumeroDocConductor.ToString(); await eventoBLL.GuardarEventoLogistico(evento); } }); //Log.Debug("TAG", "Funciona Inicio " + i + " long " + location.Latitude + " lat " + location.Longitude + " - " + _address); //else { // //Log.Debug("TAG", "Funciona Inicio Sin viaje activo " + i); //} } } catch { } }
void ibtnGps_Click(object sender, EventArgs e) { if (!this.geolocator.IsGeolocationAvailable || !this.geolocator.IsGeolocationEnabled) { alert.SetMessage("Internet o GPS estan desactivados"); alert.Show(); return; } //GPS NUEVO this.geolocator.GetPositionAsync(timeout: 10000).ContinueWith(t => { Console.WriteLine ("Position Status: {0}", t.Result.Timestamp); Console.WriteLine ("Position Latitude: {0}", t.Result.Latitude); Console.WriteLine ("Position Longitude: {0}", t.Result.Longitude); Geocoder geoCoder = new Geocoder(this); IList<Address> gotAddresses = null; gotAddresses = geoCoder.GetFromLocation(t.Result.Latitude, t.Result.Longitude, 1); this.address = (Address)gotAddresses[0]; this.address.Latitude = t.Result.Latitude; this.address.Longitude = t.Result.Longitude; mMap.AnimateCamera(CameraUpdateFactory.NewLatLngZoom(new LatLng(t.Result.Latitude, t.Result.Longitude), 16)); addCustomMarker(t.Result.Latitude, t.Result.Longitude); }, TaskScheduler.FromCurrentSynchronizationContext()); //GPS OBSOLETO /*bool isGPSEnabled = _locationManager.IsProviderEnabled(LocationManager.GpsProvider); ConnectivityManager cm = (ConnectivityManager)GetSystemService(Context.ConnectivityService); bool dataConnection = cm.GetAllNetworkInfo() != null; int resultCode = GooglePlayServicesUtil.IsGooglePlayServicesAvailable(this); if (!isGPSEnabled||!dataConnection||ConnectionResult.Success != resultCode) { alert.SetMessage("Internet o GPS estan desactivados"); alert.Show(); } else { if (_currentLocation == null) { alert.SetMessage("No se pudo ubicar la posicion"); alert.Show(); } else { Geocoder geocoder = new Geocoder(this); //IList<Address> addressList = await geocoder.GetFromLocationAsync(_currentLocation.Latitude, _currentLocation.Longitude, 10); addCustomMarker(_currentLocation.Latitude, _currentLocation.Longitude); mMap.AnimateCamera(CameraUpdateFactory.NewLatLngZoom(new LatLng(_currentLocation.Latitude, _currentLocation.Longitude), 10)); } }*/ }
private void mMap_MarkerDragEnd(object sender, GoogleMap.MarkerDragEndEventArgs e) { Geocoder geoCoder = new Geocoder(this); IList<Address> gotAddresses = null; gotAddresses = geoCoder.GetFromLocation(e.Marker.Position.Latitude, e.Marker.Position.Longitude,1); if (gotAddresses.Count > 0) { address = (Address)gotAddresses[0]; e.Marker.ShowInfoWindow(); } }
public void buscarLocacion() { //if (e.ActionId == Android.Views.InputMethods.ImeAction.Done) //{ Geocoder geoCoder = new Geocoder(this); IList<Address> gotAddresses = null; gotAddresses = geoCoder.GetFromLocationName(txtBuscar.Text, 1); if (gotAddresses.Count > 0) { address = (Address)gotAddresses[0]; Console.WriteLine("Country name: {0}\n Extras: {1}\n Feature Name: {2}\n Latitude: {3}\n Localty: {4}\n Longitude: {5}\n Thtoughfare: {6}", address.CountryName, address.Extras, address.FeatureName, address.Latitude, address.Locality, address.Longitude, address.Thoroughfare); mMap.AnimateCamera(CameraUpdateFactory.NewLatLngZoom(new LatLng(address.Latitude, address.Longitude), 16)); txtBuscar.ClearFocus(); InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService); imm.HideSoftInputFromWindow(txtBuscar.WindowToken, 0); addCustomMarker(address.Latitude, address.Longitude); } else { alert.SetMessage("No hay coincidencias"); alert.Show(); } //} //else //{ // e.Handled = false; //} }