Skip to content

Commit

Permalink
Fix reverse and direction address
Browse files Browse the repository at this point in the history
  • Loading branch information
lowzonenose committed Dec 11, 2023
1 parent 4f37c5d commit 3cb4e76
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
17 changes: 10 additions & 7 deletions src/js/directions/directions.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,14 @@ class Directions {
bResponse = false;
}).finally(() => {
var target = null;
var c = (bResponse) ? Reverse.getCoordinates() : {lon : coordinates.lng, lat : coordinates.lat};
var a = (bResponse) ? Reverse.getAddress() : c.lon.toFixed(6) + ", " + c.lat.toFixed(6);
var address = a;
if (bResponse) {
address = a.street + ", " + a.city + ", " + a.citycode;
var coords = Reverse.getCoordinates() || {lon : coordinates.lng, lat : coordinates.lat};
var address = Reverse.getAddress() || coords.lon.toFixed(6) + ", " + coords.lat.toFixed(6);
var strAddress = address;
if (typeof address !== "string") {
strAddress = "";
strAddress += (address.number !== "") ? address.number + " " : "";
strAddress += (address.street !== "") ? address.street + ", " : "";
strAddress += address.city + ", " + address.postcode;
}
// start
if (index === 0) {
Expand All @@ -326,8 +329,8 @@ class Directions {
}
// on ajoute les resultats dans le contrôle
if (target) {
target.dataset.coordinates = "[" + c.lon + "," + c.lat + "]";
target.value = address;
target.dataset.coordinates = "[" + coords.lon + "," + coords.lat + "]";
target.value = strAddress;
}
});
}
Expand Down
17 changes: 15 additions & 2 deletions src/js/services/reverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const compute = async (coordinates) => {
number : number,
street : street,
postcode : postcode,
city : city,
city : city
};

results = {
Expand All @@ -96,15 +96,28 @@ const compute = async (coordinates) => {
* { lon lat }
*/
const getCoordinates = () => {
if (!results) {
return null;
}
return results.coordinates;
};

/**
* obtenir l'adresse
* @example
* { number street citycode city }
* { number street postcode city }
*/
const getAddress = () => {
if (!results) {
return null;
}
if (results &&
results.address.number === "" &&
results.address.street === "" &&
results.address.postcode === "" &&
results.address.city === "") {
return null;
}
return results.address;
};

Expand Down

0 comments on commit 3cb4e76

Please sign in to comment.