-
-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathplacemark.dart
More file actions
163 lines (141 loc) · 4.95 KB
/
placemark.dart
File metadata and controls
163 lines (141 loc) · 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import 'package:meta/meta.dart';
/// Contains detailed placemark information.
@immutable
class Placemark {
/// Constructs an instance with the given values for testing. [Placemark]
/// instances constructed this way won't actually reflect any real information
/// from the platform, just whatever was passed in at construction time.
const Placemark({
this.name,
this.street,
this.isoCountryCode,
this.country,
this.postalCode,
this.administrativeArea,
this.subAdministrativeArea,
this.locality,
this.subLocality,
this.thoroughfare,
this.subThoroughfare,
});
const Placemark._({
this.name,
this.street,
this.isoCountryCode,
this.country,
this.postalCode,
this.administrativeArea,
this.subAdministrativeArea,
this.locality,
this.subLocality,
this.thoroughfare,
this.subThoroughfare,
});
/// The name associated with the placemark.
final String? name;
/// The street associated with the placemark.
final String? street;
/// The abbreviated country name, according to the two letter (alpha-2) [ISO standard](https://www.iso.org/iso-3166-country-codes.html).
final String? isoCountryCode;
/// The name of the country associated with the placemark.
final String? country;
/// The postal code associated with the placemark.
final String? postalCode;
/// The name of the state or province associated with the placemark.
final String? administrativeArea;
/// Additional administrative area information for the placemark.
final String? subAdministrativeArea;
/// The name of the city associated with the placemark.
final String? locality;
/// Additional city-level information for the placemark.
final String? subLocality;
/// The street address associated with the placemark.
final String? thoroughfare;
/// Additional street address information for the placemark.
final String? subThoroughfare;
@override
bool operator ==(Object other) =>
other is Placemark &&
other.administrativeArea == administrativeArea &&
other.country == country &&
other.isoCountryCode == isoCountryCode &&
other.locality == locality &&
other.name == name &&
other.postalCode == postalCode &&
other.street == street &&
other.subAdministrativeArea == subAdministrativeArea &&
other.subLocality == subLocality &&
other.subThoroughfare == subThoroughfare &&
other.thoroughfare == thoroughfare;
@override
int get hashCode =>
administrativeArea.hashCode ^
country.hashCode ^
isoCountryCode.hashCode ^
locality.hashCode ^
name.hashCode ^
postalCode.hashCode ^
street.hashCode ^
subAdministrativeArea.hashCode ^
subLocality.hashCode ^
subThoroughfare.hashCode ^
thoroughfare.hashCode;
/// Converts a list of [Map] instances to a list of [Placemark] instances.
static List<Placemark> fromMaps(dynamic message) {
if (message == null) {
throw ArgumentError('The parameter \'message\' should not be null.');
}
final List<Placemark> list = message.map<Placemark>(fromMap).toList();
return list;
}
/// Converts the supplied [Map] to an instance of the [Placemark] class.
static Placemark fromMap(dynamic message) {
if (message == null) {
throw ArgumentError('The parameter \'message\' should not be null.');
}
final Map<dynamic, dynamic> placemarkMap = message;
return Placemark._(
name: placemarkMap['name'] ?? '',
street: placemarkMap['street'] ?? '',
isoCountryCode: placemarkMap['isoCountryCode'] ?? '',
country: placemarkMap['country'] ?? '',
postalCode: placemarkMap['postalCode'] ?? '',
administrativeArea: placemarkMap['administrativeArea'] ?? '',
subAdministrativeArea: placemarkMap['subAdministrativeArea'] ?? '',
locality: placemarkMap['locality'] ?? '',
subLocality: placemarkMap['subLocality'] ?? '',
thoroughfare: placemarkMap['thoroughfare'] ?? '',
subThoroughfare: placemarkMap['subThoroughfare'] ?? '',
);
}
/// Converts the [Placemark] instance into a [Map] instance that can be
/// serialized to JSON.
Map<String, dynamic> toJson() => {
'name': name,
'street': street,
'isoCountryCode': isoCountryCode,
'country': country,
'postalCode': postalCode,
'administrativeArea': administrativeArea,
'subAdministrativeArea': subAdministrativeArea,
'locality': locality,
'subLocality': subLocality,
'thoroughfare': thoroughfare,
'subThoroughfare': subThoroughfare,
};
@override
String toString() {
return '''
Name: $name,
Street: $street,
ISO Country Code: $isoCountryCode,
Country: $country,
Postal code: $postalCode,
Administrative area: $administrativeArea,
Subadministrative area: $subAdministrativeArea,
Locality: $locality,
Sublocality: $subLocality,
Thoroughfare: $thoroughfare,
Subthoroughfare: $subThoroughfare''';
}
}