Skip to content
Snippets Groups Projects
Commit 80f0b99e authored by Hugo SUBTIL's avatar Hugo SUBTIL
Browse files

fix: location decline

parent f45ca1d7
No related branches found
No related tags found
1 merge request!31Recette
...@@ -38,13 +38,9 @@ export class HomeComponent implements OnInit { ...@@ -38,13 +38,9 @@ export class HomeComponent implements OnInit {
if (structures) { if (structures) {
Promise.all( Promise.all(
structures.map((structure) => { structures.map((structure) => {
if (this.geolocation) { return this.getStructurePosition(structure).then((val) => {
return this.getStructurePosition(structure).then((val) => { return this.structureService.updateOpeningStructure(val, DateTime.local());
return this.structureService.updateOpeningStructure(val, DateTime.local()); });
});
} else {
return this.structureService.updateOpeningStructure(structure, DateTime.local());
}
}) })
).then((structureList) => { ).then((structureList) => {
structureList = _.sortBy(structureList, ['distance']); structureList = _.sortBy(structureList, ['distance']);
...@@ -85,16 +81,19 @@ export class HomeComponent implements OnInit { ...@@ -85,16 +81,19 @@ export class HomeComponent implements OnInit {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.getCoord(structure.n, structure.voie, structure.commune).subscribe((coord: GeoJson) => { this.getCoord(structure.n, structure.voie, structure.commune).subscribe((coord: GeoJson) => {
structure.address = structure.voie + ' - ' + coord.properties.postcode + ' ' + coord.properties.city; structure.address = structure.voie + ' - ' + coord.properties.postcode + ' ' + coord.properties.city;
structure.distance = parseInt( // If location available, process structure distance
this.geoJsonService.getDistance( if (this.currentLocation) {
coord.geometry.getLon(), structure.distance = parseInt(
coord.geometry.getLat(), this.geoJsonService.getDistance(
this.currentLocation.geometry.getLon(), coord.geometry.getLon(),
this.currentLocation.geometry.getLat(), coord.geometry.getLat(),
'M' this.currentLocation.geometry.getLon(),
), this.currentLocation.geometry.getLat(),
10 'M'
); ),
10
);
}
resolve(structure); resolve(structure);
}); });
}); });
...@@ -109,13 +108,20 @@ export class HomeComponent implements OnInit { ...@@ -109,13 +108,20 @@ export class HomeComponent implements OnInit {
} }
public getLocation(): void { public getLocation(): void {
navigator.geolocation.getCurrentPosition((position) => { navigator.geolocation.getCurrentPosition(
this.geolocation = true; (position) => {
const longitude = position.coords.longitude; this.geolocation = true;
const latitude = position.coords.latitude; const longitude = position.coords.longitude;
this.getAddress(longitude, latitude); const latitude = position.coords.latitude;
this.getStructures(null); this.getAddress(longitude, latitude);
}); this.getStructures(null);
},
(err) => {
if (err.PERMISSION_DENIED) {
this.getStructures(null);
}
}
);
} }
private getAddress(longitude: number, latitude: number): void { private getAddress(longitude: number, latitude: number): void {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment