use new zip code API (old one is deprecated)

master
Nadim Salloum 2023-12-20 22:51:14 +01:00
parent 3f0ab15f56
commit ad10d61c04
Signed by untrusted user who does not match committer: nadim
GPG Key ID: 649BDF978504C1D1
1 changed files with 8 additions and 6 deletions

View File

@ -91,14 +91,16 @@ export default {
methods: { methods: {
fetchCity(newVal, oldVal) { fetchCity(newVal, oldVal) {
if (newVal !== oldVal && newVal.length === 4 && this.form.country === 'CH') { if (newVal !== oldVal && newVal.length === 4 && this.form.country === 'CH') {
axios.get(`https://swisspost.opendatasoft.com/api/records/1.0/search/?dataset=plz_verzeichnis_v2&q=&facet=ortbez18&refine.postleitzahl=${newVal}`) axios.get(`https://openplzapi.org/ch/Localities?postalCode=${newVal}`)
.then((response) => { .then((response) => {
let records = response.data.records; console.log(response);
if (records.length > 1) { let data = response.data;
console.log(data);
/*if (records.length > 1) {
records = records.filter(rec => rec.geometry); records = records.filter(rec => rec.geometry);
} }*/
if (records[0]) { if (data[0]) {
this.form.city = records[0].fields.ortbez18; this.form.city = data[0].name;
} }
}); });
} }