use new zip code API (old one is deprecated)
parent
3f0ab15f56
commit
ad10d61c04
|
|
@ -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;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue