new location with locationIQ Model and service

This commit is contained in:
2026-02-18 08:20:37 +01:00
parent f730dabca2
commit 191652c886
6 changed files with 324 additions and 74 deletions

View File

@@ -0,0 +1,112 @@
class LocationIQ {
String? placeId;
String? licence;
String? osmType;
String? osmId;
String? lat;
String? lon;
String? displayName;
Address? address;
List<String>? boundingbox;
LocationIQ({
this.placeId,
this.licence,
this.osmType,
this.osmId,
this.lat,
this.lon,
this.displayName,
this.address,
this.boundingbox,
});
LocationIQ.fromJson(Map<String, dynamic> json) {
placeId = json['place_id'];
licence = json['licence'];
osmType = json['osm_type'];
osmId = json['osm_id'];
lat = json['lat'];
lon = json['lon'];
displayName = json['display_name'];
address = json['address'] != null
? Address.fromJson(json['address'])
: null;
boundingbox = json['boundingbox'].cast<String>();
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['place_id'] = placeId;
data['licence'] = licence;
data['osm_type'] = osmType;
data['osm_id'] = osmId;
data['lat'] = lat;
data['lon'] = lon;
data['display_name'] = displayName;
if (address != null) {
data['address'] = address!.toJson();
}
data['boundingbox'] = boundingbox;
return data;
}
}
class Address {
String? houseNumber;
String? road;
String? village;
String? county;
String? state;
String? postcode;
String? country;
String? countryCode;
// Optional: Kurzadresse für einfachere Anzeige
String? shortAddress;
Address({
this.houseNumber,
this.road,
this.village,
this.county,
this.state,
this.postcode,
this.country,
this.countryCode,
// Optional: Kurzadresse generieren
this.shortAddress,
});
Address.fromJson(Map<String, dynamic> json) {
houseNumber = json['house_number'];
road = json['road'];
village = json['village'];
county = json['county'];
state = json['state'];
postcode = json['postcode'];
country = json['country'];
countryCode = json['country_code'];
// Optional: Kurzadresse generieren (z.B. "Test Street 123, 4812 Test Village")
shortAddress = [
if (road != null) road,
if (houseNumber != null) '$houseNumber,',
if (postcode != null) postcode,
if (village != null) '$village,',
if (county != null) '$county',
].join(' ');
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['house_number'] = houseNumber;
data['road'] = road;
data['village'] = village;
data['county'] = county;
data['state'] = state;
data['postcode'] = postcode;
data['country'] = country;
data['country_code'] = countryCode;
data['short_address'] = shortAddress;
return data;
}
}