Skip to content

Instantly share code, notes, and snippets.

@Zoomelectrico
Created October 24, 2018 12:55
Show Gist options
  • Save Zoomelectrico/2f9d6f51e5eb8c09691094ce9eef6a96 to your computer and use it in GitHub Desktop.
Save Zoomelectrico/2f9d6f51e5eb8c09691094ce9eef6a96 to your computer and use it in GitHub Desktop.
Implementacion de la funcion despachar con algunos cambios
async despachar(e: any) {
if (this.select) {
this.db
.object(`ubicacionGPS/${e.key}`)
.valueChanges()
.subscribe((ubicacion: any) => {
this.db
.object(`transportes/${this.select}`)
.valueChanges()
.subscribe((transporte: any) => {
const { lat, lon } = transporte;
let { latitud, longitud } = ubicacion;
latitud = parseFloat(latitud);
longitud = parseFloat(longitud);
let latitud2 = parseFloat(this.translateToDecimal(lat)),
longitud2 = parseFloat(this.translateToDecimal(lon));
if (longitud2 > 0) {
longitud2 = longitud2 * -1;
}
const distance =
((latitud2 - latitud) ** 2 + (longitud2 - longitud) ** 2) **
(1 / 2);
if (distance <= 0.00045009887) {
this.db.object(`ubicacionGPS/${e.key}`).update({
camion: this.select
});
this.encomiendas = this.encomiendas.filter(
en => en["key"] != e.key
);
this.message = `la encomienda ${e.key} se ha cargado a ${
this.select
}`;
} else {
this.message = `
No es posible colocar la encomienda en el Transporte.
Estan en lugares distintos.
lat1:${la1} lat2:${la2}`;
}
});
});
} else {
this.message = "No se olvide de seleccionar un transporte";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment