public async void actualzarRepartidorMetodo(object sender, EventArgs e) { string baseurl = "http://scmrocket.azurewebsites.net/api/pedidos/" + id.ToString(); var Client = new HttpClient(); Client.MaxResponseContentBufferSize = 256000; var uril = new Uri(baseurl); var response = Client.GetAsync(uril).Result; if (response.IsSuccessStatusCode) { var content = response.Content.ReadAsStringAsync().Result; var items = JsonConvert.DeserializeObject <PedidoModel>(content); Android.Locations.Location puntoa = new Android.Locations.Location("punto A"); Android.Locations.Location puntob = new Android.Locations.Location("punto B"); puntoa.Latitude = items.latitud; puntoa.Longitude = items.longitud; puntob.Latitude = await latitude(); puntob.Longitude = await longitud(); items.latitudRep = puntob.Latitude; items.longitudRep = puntob.Longitude; distanciaRepartidor.Text = puntoa.DistanceTo(puntob).ToString(); if (Postear(items)) { Toast.MakeText(ApplicationContext, "Actualizado", ToastLength.Long).Show(); } else { Toast.MakeText(ApplicationContext, "Error al actualizar", ToastLength.Long).Show(); } } }
/// <summary> /// On Google play services Connection handling /// </summary> /// <param name="connectionHint"></param> async public void OnConnected(Bundle connectionHint) { Android.Locations.Location location = await mFusedLocationProviderClient.GetLastLocationAsync(); SetLastKnownLocation(location); if (CurrentRequestType == RequestType.Add) { AddGeofences(); StartLocationUpdates(); } else if (CurrentRequestType == RequestType.Clear) { RemoveGeofences(); } else if (CurrentRequestType == RequestType.Delete) { if (mRequestedRegionIdentifiers != null) { RemoveGeofences(mRequestedRegionIdentifiers); } } CurrentRequestType = RequestType.Default; System.Diagnostics.Debug.WriteLine("Connection obtained, starting service"); }
/// <summary> /// Raises the connected event. /// </summary> /// <param name="connectionHint">Connection hint.</param> public void OnConnected(Bundle connectionHint) { Android.Locations.Location location = Android.Gms.Location.LocationServices.FusedLocationApi.GetLastLocation(this.modeGoogleApiClient); this.SetLastKnownLocation(location); switch (this.CurrentRequestType) { case RequestType.Add: this.AddGeofences(); this.StartLocationUpdates(); break; case RequestType.Clear: this.RemoveGeofences(); break; case RequestType.Delete: if (this.modeRequestedRegionIdentifiers != null) { this.RemoveGeofences(this.modeRequestedRegionIdentifiers); } break; } this.CurrentRequestType = RequestType.Default; }
void HomeFragment_CurrentLocation(object sender, LocationCallBackHelper.OnLocationCapturedEventArgs e) { mLastLocation = e.Location; mLastLatLng = new LatLng(mLastLocation.Latitude, mLastLocation.Longitude); if (AvailabilityListener != null) { AvailabilityListener.UpDateLocation(mLastLocation); } if (availabilityStatus && AvailabilityListener == null) { TakeDriverOnline(); } if (status == "ACCEPTED") { //Update and Animate driver movement to pick up location LatLng pickupLatLng = new LatLng(newRideDetails.PickupLat, newRideDetails.PickupLng); mapHelper.UpdateMovement(mLastLatLng, pickupLatLng, "Rider"); //update location in riderrequest table, so that rider can recieve updates newTripEventListener.UpdateLocation(mLastLocation); } else if (status == "ARRIVED") { newTripEventListener.UpdateLocation(mLastLocation); } else if (status == "ONTRIP") {//Update and animate driver movement to destination LatLng destinationLatLng = new LatLng(newRideDetails.DestinationLat, newRideDetails.DestinationLng); mapHelper.UpdateMovement(mLastLatLng, destinationLatLng, "Destination"); newTripEventListener.UpdateLocation(mLastLocation); } }
public void OnLocationChanged(Android.Locations.Location location) { // Show latest location var l = DescribeLocation(location); textLocationUpdates.Text = l + System.Environment.NewLine + textLocationUpdates.Text; }
private void MLocationCallbackHelper_MyLocation(object sender, LocationCallbackHelper.OnLocationCapturedEventArgs e) { myLastLoc = e.Location; LatLng mypos = new LatLng(myLastLoc.Latitude, myLastLoc.Longitude); mainMap.AnimateCamera(CameraUpdateFactory.NewLatLngZoom(mypos, 16)); }
private static MvxGeoLocation CreateLocation(Android.Locations.Location androidLocation) { var position = new MvxGeoLocation { Timestamp = androidLocation.Time.FromMillisecondsUnixTimeToUtc() }; var coords = position.Coordinates; coords.Latitude = androidLocation.Latitude; coords.Longitude = androidLocation.Longitude; if (androidLocation.HasAltitude) { coords.Altitude = androidLocation.Altitude; } if (androidLocation.HasBearing) { coords.Heading = androidLocation.Bearing; } if (androidLocation.HasSpeed) { coords.Speed = androidLocation.Speed; } if (androidLocation.HasAccuracy) { coords.Accuracy = androidLocation.Accuracy; } return(position); }
internal void OnLocationUpdated(Android.Locations.Location androidLocation) { if (androidLocation == null) { MvxTrace.Trace("Android: Null location seen"); return; } if (androidLocation.Latitude == double.MaxValue || androidLocation.Longitude == double.MaxValue) { MvxTrace.Trace("Android: Invalid location seen"); return; } MvxGeoLocation location; try { location = CreateLocation(androidLocation); } catch (ThreadAbortException) { throw; } catch (Exception exception) { MvxTrace.Trace("Android: Exception seen in converting location " + exception.ToLongString()); return; } SendLocation(location); }
float CalculateDistance(Animal a, Android.Locations.Location l) { double altitude = Math.Pow(a.altitude - l.Altitude, 2); double latitude = Math.Pow(a.latitude - l.Latitude, 2); return(Convert.ToSingle(Math.Sqrt(altitude + latitude))); }
void HomeFragment_CurrentLocation(object sender, Helpers.LocationCallbackHelper.OnLocationCaptionEventArgs e) { _mLastLocation = e.Location; _mLastLatLng = new LatLng(_mLastLocation.Latitude, _mLastLocation.Longitude); _availablityListener?.UpdateLocation(_mLastLocation); if (_availablityStatus && _availablityListener == null) { TakeDriverOnline(); } if (_status == "ACCEPTED") { LatLng pickupLatLng = new LatLng(_newRideDetails.PickupLat, _newRideDetails.PickupLng); _mapHelper.UpdateMovement(_mLastLatLng, pickupLatLng, "Rider"); _newTripEventListener.UpdateLocation(_mLastLocation); } else if (_status == "ARRIVED") { _newTripEventListener.UpdateLocation(_mLastLocation); } else if (_status == "ONTRIP") { LatLng destinationLatLng = new LatLng(_newRideDetails.DestinationLat, _newRideDetails.DestinationLng); _mapHelper.UpdateMovement(_mLastLatLng, destinationLatLng, "Destination"); _newTripEventListener.UpdateLocation(_mLastLocation); } }
private void GPSLocationButton_Click(object sender, EventArgs eventArgs) { GPSTracker GPSTracker = new GPSTracker(); Android.Locations.Location location = GPSTracker.GPSCoordinate(); if (!GPSTracker.isLocationGPSEnabled) { ShowSettingsAlert(); } if (location == null) { MessageDialog messageDialog = new MessageDialog(); messageDialog.SendToast("Unable to get location"); } else { tvfLatLong.Text = "Lat: " + location.Latitude.ToString() + " Long: " + location.Longitude.ToString(); accuracyMessage.Text = String.Format("Accurate to {0} Meters", location.Accuracy.ToString()); Location.GPSCoordinates = new GPSCoordinate() { Longitude = location.Longitude.ToString(), Latitude = location.Latitude.ToString() }; } }
internal static Position ToPosition(this Android.Locations.Location location) { var p = new Position(); if (location.HasAccuracy) { p.Accuracy = location.Accuracy; } if (location.HasAltitude) { p.Altitude = location.Altitude; } if (location.HasBearing) { p.Heading = location.Bearing; } if (location.HasSpeed) { p.Speed = location.Speed; } p.Longitude = location.Longitude; p.Latitude = location.Latitude; p.Timestamp = location.GetTimestamp(); return(p); }
private void BPLocationButton_Click(object sender, EventArgs eventArgs) { GPSTracker GPSTracker = new GPSTracker(); Android.Locations.Location location = GPSTracker.GPSCoordinate(); if (!GPSTracker.isLocationGPSEnabled) { ShowSettingsAlert(); } if (location == null) { MessageDialog messageDialog = new MessageDialog(); messageDialog.SendToast("Unable to get location"); } else { BoundryPolygon BoundryPolygon = new BoundryPolygon() { Latitude = location.Latitude.ToString(), Longitude = location.Longitude.ToString() }; _BoundryPolygons.Add(BoundryPolygon); itemList.Add("Lat: " + location.Latitude.ToString() + " Long: " + location.Longitude.ToString()); boundaryPolygonsText.Text = String.Format("Boundary Polygons {0}", itemList.Count); arrayAdapter = new ArrayAdapter <string>(this, Resource.Layout.list_item, itemList); bpListView.Adapter = arrayAdapter; bpListView.ItemLongClick += Adapter_ItemSwipe; ViewGroup.LayoutParams param = bpListView.LayoutParameters; param.Height = 80 * _BoundryPolygons.Count(); bpListView.LayoutParameters = param; } }
void MLocationCallback_MyLocation(object sender, LocationCallbackHelper.OnLocationCapturedEventArgs e) { mLastLocation = e.Location; LatLng myposition = new LatLng(mLastLocation.Latitude, mLastLocation.Longitude); mainMap.AnimateCamera(CameraUpdateFactory.NewLatLngZoom(myposition, 17)); }
private void MLocationCallback_OnLocationFound(object sender, LocationCallbackHelper.OnLocationCapturedEventArgs e) { myLastLocation = e.Location; // Updates Location when app is normal if (!directionDrawn) { if (myLastLocation != null) { mypostion = new LatLng(myLastLocation.Latitude, myLastLocation.Longitude); map.AnimateCamera(CameraUpdateFactory.NewLatLngZoom(mypostion, 15)); } } // Updates Location When Trip stared if (tripStarted) { if (myLastLocation != null) { string key = Resources.GetString(Resource.String.mapkey); mypostion = new LatLng(myLastLocation.Latitude, myLastLocation.Longitude); mapHelper.UpdateLocationToDestination(mypostion, destinationPoint, map, key); } } }
public void actualizarMetodo(object sender, EventArgs e) { string baseurl = "http://scmrocket.azurewebsites.net/api/pedidos/" + id.ToString(); var Client = new HttpClient(); Client.MaxResponseContentBufferSize = 256000; var uril = new Uri(baseurl); var response = Client.GetAsync(uril).Result; if (response.IsSuccessStatusCode) { var content = response.Content.ReadAsStringAsync().Result; var items = JsonConvert.DeserializeObject <PedidoModel>(content); if (items.estado != "Finalizado") { estadoPedido.Text = items.estado; Android.Locations.Location puntoa = new Android.Locations.Location("punto A"); Android.Locations.Location puntob = new Android.Locations.Location("punto B"); puntoa.Latitude = items.latitud; puntoa.Longitude = items.longitud; puntob.Latitude = items.latitudRep; puntob.Longitude = items.longitudRep; distancia.Text = puntoa.DistanceTo(puntob).ToString(); estadoPedido.Text = items.estado; } else if (items.estado == "Finalizado") { Toast.MakeText(ApplicationContext, "El repartidor ha finalizado", ToastLength.Long).Show(); Intent intento = new Intent(this, typeof(MainActivity)); StartActivity(intento); } } }
private void MudancaLocalizacao() { if (ControleMapa.LocalizacaoAtual != null) { if (marcadorPosicao != null) { marcadorPosicao.Remove(); } MarkerOptions options = new MarkerOptions().SetPosition(GMap.CameraPosition.Target).SetTitle("").SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.dot)).Visible(false); marcadorPosicao = GMap.AddMarker(options); marcadorPosicao.Position = new LatLng(ControleMapa.LocalizacaoAtual.Latitude, ControleMapa.LocalizacaoAtual.Longitude); marcadorPosicao.Visible = true; if (ultimaLocalizacao != null) { var distancia = ultimaLocalizacao.DistanceTo(ControleMapa.LocalizacaoAtual); if (distancia > 2) { Bearing = ultimaLocalizacao.BearingTo(ControleMapa.LocalizacaoAtual); txtAngle.Text = Bearing.ToString() + "º"; if (modoDirecao) { Orientacao(); } } } ultimaLocalizacao = ControleMapa.LocalizacaoAtual; } }
public DroidGeoLocation(Android.Locations.Location location) { TimeStamp = DateTime.Now; Latitude = location.Latitude; Longitude = location.Longitude; Heading = location.Bearing; Speed = location.Speed; }
internal static Location ToLocation(this AndroidLocation location) => new Location { Latitude = location.Latitude, Longitude = location.Longitude, TimestampUtc = location.GetTimestamp().ToUniversalTime(), Accuracy = location.HasAccuracy ? location.Accuracy : (float?)null };
string DescribeLocation(Android.Locations.Location location) { return(string.Format("{0}: {1}, {2} @ {3}", location.Provider, location.Latitude, location.Longitude, new DateTime(1970, 1, 1, 0, 0, 0).AddMilliseconds(location.Time))); }
public void UpdateCachedLocation(Android.Locations.Location location) { if (CachedUserLocation is null) { return; } CachedUserLocation.Latitude = location.Latitude; CachedUserLocation.Longitude = location.Longitude; }
public void OnLocationChanged(Android.Locations.Location location) { if (this.PositionChanged != null) { this.PositionChanged(this, new PositionEventArgs(new Position { Latitude = location.Latitude, Longitude = location.Longitude })); } }
public static GpsLocation Convert(Android.Locations.Location loc) { GpsLocation converted = new GpsLocation(); converted.Altitude = loc.Altitude; converted.Longitude = loc.Longitude; converted.Latitude = loc.Latitude; return(converted); }
public void OnLocationChangedInternal(Location location) { Henspe.Current.myLocation = location; if (henspeFragment != null) { henspeFragment.UpdateLocation(location); } }
private async void GetLocation() { if (!CheckPermission()) { Toast.MakeText(this, "No permission", ToastLength.Long).Show(); return; } lastLocation = await locationClient.GetLastLocationAsync(); }
public void OnLocationChanged(Android.Locations.Location location) { var evt = LocationChanged; if (evt != null) { evt(location); } }
public void SetData(Controls.LocationQueryViewModel query_vm, Android.Locations.Location location) { query = query_vm.LocationQuery; name = query_vm.LocationName; latitude = location.Latitude; longitude = location.Longitude; tz_long = query_vm.LocationTZ_Long; locationType = LocationType.GPS; source = Settings.API; }
private void RefashAccuracy_Click(object sender, EventArgs e) { GPSTracker GPSTracker = new GPSTracker(); Android.Locations.Location location = GPSTracker.GPSCoordinate(); if (location != null) { accuracyMessage.Text = String.Format("Accurate to {0} Meters", location.Accuracy.ToString()); } }
public void AddLandmark(string description, double latitude, double longitude) { // consider only allowing unique adds. For now, whatever. Android.Locations.Location landmark = new Android.Locations.Location(description) { Latitude = latitude, Longitude = longitude }; Landmarks.Add(landmark); }
public static double CalculateGeopositionDistance(Android.Locations.Location position1, Android.Locations.Location position2) { double lat1 = position1.Latitude; double lon1 = position1.Longitude; double lat2 = position2.Latitude; double lon2 = position2.Longitude; /* Returns value in meters */ return(Math.Abs(CalculateHaversine(lat1, lon1, lat2, lon2))); }
public static void setCurrentLocationInfo(Android.Locations.Location location) { currentLocationInfo = location; }