@capgo/nativegeocoder 7.2.4 → 7.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/ee/forgr/capacitor_nativegeocoder/NativeGeocoder.java +198 -306
- package/android/src/main/java/ee/forgr/capacitor_nativegeocoder/NativeGeocoderPlugin.java +23 -23
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +4 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.d.ts +2 -2
- package/dist/esm/web.js +25 -37
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +25 -37
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +25 -37
- package/dist/plugin.js.map +1 -1
- package/package.json +2 -2
|
@@ -15,332 +15,224 @@ import org.json.JSONObject;
|
|
|
15
15
|
|
|
16
16
|
class NativeGeocoderOptions {
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
boolean useLocale = true;
|
|
19
|
+
String defaultLocale = null;
|
|
20
|
+
int maxResults = 1;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
public class NativeGeocoder {
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
private Geocoder geocoder;
|
|
26
|
+
public Context context;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Reverse geocode a given latitude and longitude to find location address
|
|
30
|
+
* @param latitude double
|
|
31
|
+
* @param longitude double
|
|
32
|
+
* @param call PluginCall
|
|
33
|
+
*/
|
|
34
|
+
public void reverseGeocode(double latitude, double longitude, PluginCall call) {
|
|
35
|
+
if (latitude == 0 || longitude == 0) {
|
|
36
|
+
call.reject("Expected two non-empty double arguments.");
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
27
39
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
* @param call PluginCall
|
|
33
|
-
*/
|
|
34
|
-
public void reverseGeocode(
|
|
35
|
-
double latitude,
|
|
36
|
-
double longitude,
|
|
37
|
-
PluginCall call
|
|
38
|
-
) {
|
|
39
|
-
if (latitude == 0 || longitude == 0) {
|
|
40
|
-
call.reject("Expected two non-empty double arguments.");
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
40
|
+
if (!Geocoder.isPresent()) {
|
|
41
|
+
call.reject("Geocoder is not present on this device/emulator.");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
NativeGeocoderOptions geocoderOptions = getNativeGeocoderOptions(call);
|
|
46
|
+
geocoder = createGeocoderWithOptions(geocoderOptions);
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
List<Address> geoResults = geocoder.getFromLocation(latitude, longitude, geocoderOptions.maxResults);
|
|
50
|
+
if (geoResults.size() > 0) {
|
|
51
|
+
int maxResultObjects = geoResults.size() >= geocoderOptions.maxResults ? geoResults.size() : geoResults.size();
|
|
52
|
+
JSONArray resultObj = new JSONArray();
|
|
53
|
+
|
|
54
|
+
for (int i = 0; i < maxResultObjects; i++) {
|
|
55
|
+
Address address = geoResults.get(i);
|
|
56
|
+
|
|
57
|
+
// https://developer.android.com/reference/android/location/Address.html
|
|
58
|
+
JSONObject placemark = new JSONObject();
|
|
59
|
+
placemark.put("latitude", !String.valueOf(address.getLatitude()).isEmpty() ? address.getLatitude() : 0);
|
|
60
|
+
placemark.put("longitude", !String.valueOf(address.getLongitude()).isEmpty() ? address.getLongitude() : 0);
|
|
61
|
+
placemark.put("countryCode", address.getCountryCode() != null ? address.getCountryCode() : "");
|
|
62
|
+
placemark.put("countryName", address.getCountryName() != null ? address.getCountryName() : "");
|
|
63
|
+
placemark.put("postalCode", address.getPostalCode() != null ? address.getPostalCode() : "");
|
|
64
|
+
placemark.put("administrativeArea", address.getAdminArea() != null ? address.getAdminArea() : "");
|
|
65
|
+
placemark.put("subAdministrativeArea", address.getSubAdminArea() != null ? address.getSubAdminArea() : "");
|
|
66
|
+
placemark.put("locality", address.getLocality() != null ? address.getLocality() : "");
|
|
67
|
+
placemark.put("subLocality", address.getSubLocality() != null ? address.getSubLocality() : "");
|
|
68
|
+
placemark.put("thoroughfare", address.getThoroughfare() != null ? address.getThoroughfare() : "");
|
|
69
|
+
placemark.put("subThoroughfare", address.getSubThoroughfare() != null ? address.getSubThoroughfare() : "");
|
|
70
|
+
placemark.put(
|
|
71
|
+
"areasOfInterest",
|
|
72
|
+
address.getFeatureName() != null ? new JSONArray(new String[] { address.getFeatureName() }) : new JSONArray()
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
resultObj.put(placemark);
|
|
76
|
+
}
|
|
77
|
+
JSObject ret = new JSObject();
|
|
78
|
+
ret.put("addresses", resultObj);
|
|
79
|
+
call.resolve(ret);
|
|
80
|
+
} else {
|
|
81
|
+
call.reject("Cannot get an address.");
|
|
82
|
+
}
|
|
83
|
+
} catch (Exception e) {
|
|
84
|
+
String errorMsg = e.getMessage();
|
|
85
|
+
if (e.getMessage().equals("grpc failed") && !isNetworkAvailable()) {
|
|
86
|
+
errorMsg = "No Internet Access";
|
|
87
|
+
}
|
|
88
|
+
call.reject("Geocoder:getFromLocationName Error: " + errorMsg);
|
|
89
|
+
}
|
|
47
90
|
}
|
|
48
91
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
int maxResultObjects = geoResults.size() >= geocoderOptions.maxResults
|
|
60
|
-
? geoResults.size()
|
|
61
|
-
: geoResults.size();
|
|
62
|
-
JSONArray resultObj = new JSONArray();
|
|
63
|
-
|
|
64
|
-
for (int i = 0; i < maxResultObjects; i++) {
|
|
65
|
-
Address address = geoResults.get(i);
|
|
66
|
-
|
|
67
|
-
// https://developer.android.com/reference/android/location/Address.html
|
|
68
|
-
JSONObject placemark = new JSONObject();
|
|
69
|
-
placemark.put(
|
|
70
|
-
"latitude",
|
|
71
|
-
!String.valueOf(address.getLatitude()).isEmpty()
|
|
72
|
-
? address.getLatitude()
|
|
73
|
-
: 0
|
|
74
|
-
);
|
|
75
|
-
placemark.put(
|
|
76
|
-
"longitude",
|
|
77
|
-
!String.valueOf(address.getLongitude()).isEmpty()
|
|
78
|
-
? address.getLongitude()
|
|
79
|
-
: 0
|
|
80
|
-
);
|
|
81
|
-
placemark.put(
|
|
82
|
-
"countryCode",
|
|
83
|
-
address.getCountryCode() != null ? address.getCountryCode() : ""
|
|
84
|
-
);
|
|
85
|
-
placemark.put(
|
|
86
|
-
"countryName",
|
|
87
|
-
address.getCountryName() != null ? address.getCountryName() : ""
|
|
88
|
-
);
|
|
89
|
-
placemark.put(
|
|
90
|
-
"postalCode",
|
|
91
|
-
address.getPostalCode() != null ? address.getPostalCode() : ""
|
|
92
|
-
);
|
|
93
|
-
placemark.put(
|
|
94
|
-
"administrativeArea",
|
|
95
|
-
address.getAdminArea() != null ? address.getAdminArea() : ""
|
|
96
|
-
);
|
|
97
|
-
placemark.put(
|
|
98
|
-
"subAdministrativeArea",
|
|
99
|
-
address.getSubAdminArea() != null ? address.getSubAdminArea() : ""
|
|
100
|
-
);
|
|
101
|
-
placemark.put(
|
|
102
|
-
"locality",
|
|
103
|
-
address.getLocality() != null ? address.getLocality() : ""
|
|
104
|
-
);
|
|
105
|
-
placemark.put(
|
|
106
|
-
"subLocality",
|
|
107
|
-
address.getSubLocality() != null ? address.getSubLocality() : ""
|
|
108
|
-
);
|
|
109
|
-
placemark.put(
|
|
110
|
-
"thoroughfare",
|
|
111
|
-
address.getThoroughfare() != null ? address.getThoroughfare() : ""
|
|
112
|
-
);
|
|
113
|
-
placemark.put(
|
|
114
|
-
"subThoroughfare",
|
|
115
|
-
address.getSubThoroughfare() != null
|
|
116
|
-
? address.getSubThoroughfare()
|
|
117
|
-
: ""
|
|
118
|
-
);
|
|
119
|
-
placemark.put(
|
|
120
|
-
"areasOfInterest",
|
|
121
|
-
address.getFeatureName() != null
|
|
122
|
-
? new JSONArray(new String[] { address.getFeatureName() })
|
|
123
|
-
: new JSONArray()
|
|
124
|
-
);
|
|
92
|
+
/**
|
|
93
|
+
* Forward geocode a given address to find coordinates
|
|
94
|
+
* @param addressString String
|
|
95
|
+
* @param call PluginCall
|
|
96
|
+
*/
|
|
97
|
+
public void forwardGeocode(String addressString, PluginCall call) {
|
|
98
|
+
if (addressString == null || addressString.length() == 0) {
|
|
99
|
+
call.reject("Expected a non-empty string argument.");
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
125
102
|
|
|
126
|
-
|
|
103
|
+
if (!Geocoder.isPresent()) {
|
|
104
|
+
call.reject("Geocoder is not present on this device/emulator.");
|
|
105
|
+
return;
|
|
127
106
|
}
|
|
128
|
-
JSObject ret = new JSObject();
|
|
129
|
-
ret.put("addresses", resultObj);
|
|
130
|
-
call.resolve(ret);
|
|
131
|
-
} else {
|
|
132
|
-
call.reject("Cannot get an address.");
|
|
133
|
-
}
|
|
134
|
-
} catch (Exception e) {
|
|
135
|
-
String errorMsg = e.getMessage();
|
|
136
|
-
if (e.getMessage().equals("grpc failed") && !isNetworkAvailable()) {
|
|
137
|
-
errorMsg = "No Internet Access";
|
|
138
|
-
}
|
|
139
|
-
call.reject("Geocoder:getFromLocationName Error: " + errorMsg);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
107
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
108
|
+
NativeGeocoderOptions geocoderOptions = getNativeGeocoderOptions(call);
|
|
109
|
+
geocoder = createGeocoderWithOptions(geocoderOptions);
|
|
110
|
+
|
|
111
|
+
try {
|
|
112
|
+
List<Address> geoResults = geocoder.getFromLocationName(addressString, geocoderOptions.maxResults);
|
|
113
|
+
|
|
114
|
+
if (geoResults.size() > 0) {
|
|
115
|
+
int maxResultObjects = geoResults.size() >= geocoderOptions.maxResults ? geoResults.size() : geoResults.size();
|
|
116
|
+
JSONArray resultObj = new JSONArray();
|
|
117
|
+
|
|
118
|
+
for (int i = 0; i < maxResultObjects; i++) {
|
|
119
|
+
Address address = geoResults.get(i);
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
String latitude = String.valueOf(address.getLatitude());
|
|
123
|
+
String longitude = String.valueOf(address.getLongitude());
|
|
124
|
+
|
|
125
|
+
if (!latitude.isEmpty() && !longitude.isEmpty()) {
|
|
126
|
+
// https://developer.android.com/reference/android/location/Address.html
|
|
127
|
+
JSObject placemark = new JSObject();
|
|
128
|
+
placemark.put("latitude", address.getLatitude());
|
|
129
|
+
placemark.put("longitude", address.getLongitude());
|
|
130
|
+
placemark.put("countryCode", address.getCountryCode() != null ? address.getCountryCode() : "");
|
|
131
|
+
placemark.put("countryName", address.getCountryName() != null ? address.getCountryName() : "");
|
|
132
|
+
placemark.put("postalCode", address.getPostalCode() != null ? address.getPostalCode() : "");
|
|
133
|
+
placemark.put("administrativeArea", address.getAdminArea() != null ? address.getAdminArea() : "");
|
|
134
|
+
placemark.put("subAdministrativeArea", address.getSubAdminArea() != null ? address.getSubAdminArea() : "");
|
|
135
|
+
placemark.put("locality", address.getLocality() != null ? address.getLocality() : "");
|
|
136
|
+
placemark.put("subLocality", address.getSubLocality() != null ? address.getSubLocality() : "");
|
|
137
|
+
placemark.put("thoroughfare", address.getThoroughfare() != null ? address.getThoroughfare() : "");
|
|
138
|
+
placemark.put("subThoroughfare", address.getSubThoroughfare() != null ? address.getSubThoroughfare() : "");
|
|
139
|
+
placemark.put(
|
|
140
|
+
"areasOfInterest",
|
|
141
|
+
address.getFeatureName() != null
|
|
142
|
+
? new JSONArray(new String[] { address.getFeatureName() })
|
|
143
|
+
: new JSONArray()
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
resultObj.put(placemark);
|
|
147
|
+
}
|
|
148
|
+
} catch (RuntimeException e) {
|
|
149
|
+
e.printStackTrace();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (resultObj.length() == 0) {
|
|
154
|
+
call.reject("Cannot get latitude and/or longitude.");
|
|
155
|
+
} else {
|
|
156
|
+
JSObject ret = new JSObject();
|
|
157
|
+
ret.put("addresses", resultObj);
|
|
158
|
+
call.resolve(ret);
|
|
159
|
+
}
|
|
160
|
+
} else {
|
|
161
|
+
call.reject("Cannot find a location.");
|
|
162
|
+
}
|
|
163
|
+
} catch (Exception e) {
|
|
164
|
+
String errorMsg = e.getMessage();
|
|
165
|
+
if (e.getMessage().equals("grpc failed") && !isNetworkAvailable()) {
|
|
166
|
+
errorMsg = "No Internet Access";
|
|
167
|
+
}
|
|
168
|
+
call.reject("Geocoder:getFromLocationName Error: " + errorMsg);
|
|
169
|
+
}
|
|
152
170
|
}
|
|
153
171
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
172
|
+
/**
|
|
173
|
+
* Get network connection
|
|
174
|
+
* @return boolean
|
|
175
|
+
*/
|
|
176
|
+
private boolean isNetworkAvailable() {
|
|
177
|
+
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
178
|
+
NetworkInfo activeNetworkInfo = null;
|
|
179
|
+
if (connectivityManager != null) {
|
|
180
|
+
activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
|
|
181
|
+
}
|
|
182
|
+
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
|
|
157
183
|
}
|
|
158
184
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
geocoderOptions
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
try {
|
|
178
|
-
String latitude = String.valueOf(address.getLatitude());
|
|
179
|
-
String longitude = String.valueOf(address.getLongitude());
|
|
180
|
-
|
|
181
|
-
if (!latitude.isEmpty() && !longitude.isEmpty()) {
|
|
182
|
-
// https://developer.android.com/reference/android/location/Address.html
|
|
183
|
-
JSObject placemark = new JSObject();
|
|
184
|
-
placemark.put("latitude", address.getLatitude());
|
|
185
|
-
placemark.put("longitude", address.getLongitude());
|
|
186
|
-
placemark.put(
|
|
187
|
-
"countryCode",
|
|
188
|
-
address.getCountryCode() != null ? address.getCountryCode() : ""
|
|
189
|
-
);
|
|
190
|
-
placemark.put(
|
|
191
|
-
"countryName",
|
|
192
|
-
address.getCountryName() != null ? address.getCountryName() : ""
|
|
193
|
-
);
|
|
194
|
-
placemark.put(
|
|
195
|
-
"postalCode",
|
|
196
|
-
address.getPostalCode() != null ? address.getPostalCode() : ""
|
|
197
|
-
);
|
|
198
|
-
placemark.put(
|
|
199
|
-
"administrativeArea",
|
|
200
|
-
address.getAdminArea() != null ? address.getAdminArea() : ""
|
|
201
|
-
);
|
|
202
|
-
placemark.put(
|
|
203
|
-
"subAdministrativeArea",
|
|
204
|
-
address.getSubAdminArea() != null
|
|
205
|
-
? address.getSubAdminArea()
|
|
206
|
-
: ""
|
|
207
|
-
);
|
|
208
|
-
placemark.put(
|
|
209
|
-
"locality",
|
|
210
|
-
address.getLocality() != null ? address.getLocality() : ""
|
|
211
|
-
);
|
|
212
|
-
placemark.put(
|
|
213
|
-
"subLocality",
|
|
214
|
-
address.getSubLocality() != null ? address.getSubLocality() : ""
|
|
215
|
-
);
|
|
216
|
-
placemark.put(
|
|
217
|
-
"thoroughfare",
|
|
218
|
-
address.getThoroughfare() != null
|
|
219
|
-
? address.getThoroughfare()
|
|
220
|
-
: ""
|
|
221
|
-
);
|
|
222
|
-
placemark.put(
|
|
223
|
-
"subThoroughfare",
|
|
224
|
-
address.getSubThoroughfare() != null
|
|
225
|
-
? address.getSubThoroughfare()
|
|
226
|
-
: ""
|
|
227
|
-
);
|
|
228
|
-
placemark.put(
|
|
229
|
-
"areasOfInterest",
|
|
230
|
-
address.getFeatureName() != null
|
|
231
|
-
? new JSONArray(new String[] { address.getFeatureName() })
|
|
232
|
-
: new JSONArray()
|
|
233
|
-
);
|
|
234
|
-
|
|
235
|
-
resultObj.put(placemark);
|
|
185
|
+
/**
|
|
186
|
+
* Get a valid NativeGeocoderOptions object
|
|
187
|
+
* @param options JSONObject
|
|
188
|
+
* @return NativeGeocoderOptions
|
|
189
|
+
*/
|
|
190
|
+
private NativeGeocoderOptions getNativeGeocoderOptions(PluginCall options) {
|
|
191
|
+
NativeGeocoderOptions geocoderOptions = new NativeGeocoderOptions();
|
|
192
|
+
|
|
193
|
+
if (options != null) {
|
|
194
|
+
geocoderOptions.useLocale = options.getBoolean("useLocale", false);
|
|
195
|
+
geocoderOptions.defaultLocale = options.getString("defaultLocale", null);
|
|
196
|
+
geocoderOptions.maxResults = options.getInt("maxResults", 1);
|
|
197
|
+
if (geocoderOptions.maxResults > 0) {
|
|
198
|
+
int MAX_RESULTS_COUNT = 5;
|
|
199
|
+
geocoderOptions.maxResults = Math.min(geocoderOptions.maxResults, MAX_RESULTS_COUNT);
|
|
200
|
+
} else {
|
|
201
|
+
geocoderOptions.maxResults = 1;
|
|
236
202
|
}
|
|
237
|
-
} catch (RuntimeException e) {
|
|
238
|
-
e.printStackTrace();
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
if (resultObj.length() == 0) {
|
|
243
|
-
call.reject("Cannot get latitude and/or longitude.");
|
|
244
203
|
} else {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
204
|
+
geocoderOptions.useLocale = true;
|
|
205
|
+
geocoderOptions.defaultLocale = null;
|
|
206
|
+
geocoderOptions.maxResults = 1;
|
|
248
207
|
}
|
|
249
|
-
} else {
|
|
250
|
-
call.reject("Cannot find a location.");
|
|
251
|
-
}
|
|
252
|
-
} catch (Exception e) {
|
|
253
|
-
String errorMsg = e.getMessage();
|
|
254
|
-
if (e.getMessage().equals("grpc failed") && !isNetworkAvailable()) {
|
|
255
|
-
errorMsg = "No Internet Access";
|
|
256
|
-
}
|
|
257
|
-
call.reject("Geocoder:getFromLocationName Error: " + errorMsg);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
208
|
|
|
261
|
-
|
|
262
|
-
* Get network connection
|
|
263
|
-
* @return boolean
|
|
264
|
-
*/
|
|
265
|
-
private boolean isNetworkAvailable() {
|
|
266
|
-
ConnectivityManager connectivityManager =
|
|
267
|
-
(ConnectivityManager) context.getSystemService(
|
|
268
|
-
Context.CONNECTIVITY_SERVICE
|
|
269
|
-
);
|
|
270
|
-
NetworkInfo activeNetworkInfo = null;
|
|
271
|
-
if (connectivityManager != null) {
|
|
272
|
-
activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
|
|
209
|
+
return geocoderOptions;
|
|
273
210
|
}
|
|
274
|
-
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
|
|
275
|
-
}
|
|
276
211
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
return geocoderOptions;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* Create a Geocoder with NativeGeocoderOptions
|
|
309
|
-
* @param geocoderOptions NativeGeocoderOptions
|
|
310
|
-
* @return Geocoder
|
|
311
|
-
*/
|
|
312
|
-
private Geocoder createGeocoderWithOptions(
|
|
313
|
-
NativeGeocoderOptions geocoderOptions
|
|
314
|
-
) {
|
|
315
|
-
if (
|
|
316
|
-
geocoderOptions.defaultLocale != null &&
|
|
317
|
-
!geocoderOptions.defaultLocale.isEmpty()
|
|
318
|
-
) {
|
|
319
|
-
Locale locale;
|
|
320
|
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
321
|
-
locale = Locale.forLanguageTag(geocoderOptions.defaultLocale);
|
|
322
|
-
} else {
|
|
323
|
-
String[] parts = geocoderOptions.defaultLocale.split("[-_]", -1);
|
|
324
|
-
if (parts.length == 1) locale = new Locale(parts[0]);
|
|
325
|
-
else if (
|
|
326
|
-
parts.length == 2 || (parts.length == 3 && parts[2].startsWith("#"))
|
|
327
|
-
) locale = new Locale(parts[0], parts[1]);
|
|
328
|
-
else locale = new Locale(parts[0], parts[1], parts[2]);
|
|
329
|
-
}
|
|
330
|
-
geocoder = new Geocoder(context.getApplicationContext(), locale);
|
|
331
|
-
} else {
|
|
332
|
-
if (geocoderOptions.useLocale) {
|
|
333
|
-
geocoder = new Geocoder(
|
|
334
|
-
context.getApplicationContext(),
|
|
335
|
-
Locale.getDefault()
|
|
336
|
-
);
|
|
337
|
-
} else {
|
|
338
|
-
geocoder = new Geocoder(
|
|
339
|
-
context.getApplicationContext(),
|
|
340
|
-
Locale.ENGLISH
|
|
341
|
-
);
|
|
342
|
-
}
|
|
212
|
+
/**
|
|
213
|
+
* Create a Geocoder with NativeGeocoderOptions
|
|
214
|
+
* @param geocoderOptions NativeGeocoderOptions
|
|
215
|
+
* @return Geocoder
|
|
216
|
+
*/
|
|
217
|
+
private Geocoder createGeocoderWithOptions(NativeGeocoderOptions geocoderOptions) {
|
|
218
|
+
if (geocoderOptions.defaultLocale != null && !geocoderOptions.defaultLocale.isEmpty()) {
|
|
219
|
+
Locale locale;
|
|
220
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
221
|
+
locale = Locale.forLanguageTag(geocoderOptions.defaultLocale);
|
|
222
|
+
} else {
|
|
223
|
+
String[] parts = geocoderOptions.defaultLocale.split("[-_]", -1);
|
|
224
|
+
if (parts.length == 1) locale = new Locale(parts[0]);
|
|
225
|
+
else if (parts.length == 2 || (parts.length == 3 && parts[2].startsWith("#"))) locale = new Locale(parts[0], parts[1]);
|
|
226
|
+
else locale = new Locale(parts[0], parts[1], parts[2]);
|
|
227
|
+
}
|
|
228
|
+
geocoder = new Geocoder(context.getApplicationContext(), locale);
|
|
229
|
+
} else {
|
|
230
|
+
if (geocoderOptions.useLocale) {
|
|
231
|
+
geocoder = new Geocoder(context.getApplicationContext(), Locale.getDefault());
|
|
232
|
+
} else {
|
|
233
|
+
geocoder = new Geocoder(context.getApplicationContext(), Locale.ENGLISH);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return geocoder;
|
|
343
237
|
}
|
|
344
|
-
return geocoder;
|
|
345
|
-
}
|
|
346
238
|
}
|
|
@@ -8,32 +8,32 @@ import com.getcapacitor.annotation.CapacitorPlugin;
|
|
|
8
8
|
@CapacitorPlugin(name = "NativeGeocoder")
|
|
9
9
|
public class NativeGeocoderPlugin extends Plugin {
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
private NativeGeocoder implementation = new NativeGeocoder();
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
@Override
|
|
14
|
+
public void load() {
|
|
15
|
+
super.load();
|
|
16
|
+
implementation.context = this.getContext();
|
|
17
|
+
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
@PluginMethod
|
|
20
|
+
public void reverseGeocode(PluginCall call) {
|
|
21
|
+
Double latitude = call.getDouble("latitude");
|
|
22
|
+
Double longitude = call.getDouble("longitude");
|
|
23
|
+
if (latitude == null || longitude == null) {
|
|
24
|
+
call.reject("Missing latitude or longitude");
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
implementation.reverseGeocode(latitude, longitude, call);
|
|
26
28
|
}
|
|
27
|
-
implementation.reverseGeocode(latitude, longitude, call);
|
|
28
|
-
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
@PluginMethod
|
|
31
|
+
public void forwardGeocode(PluginCall call) {
|
|
32
|
+
String addressString = call.getString("addressString");
|
|
33
|
+
if (addressString == null) {
|
|
34
|
+
call.reject("Missing addressString");
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
implementation.forwardGeocode(addressString, call);
|
|
36
38
|
}
|
|
37
|
-
implementation.forwardGeocode(addressString, call);
|
|
38
|
-
}
|
|
39
39
|
}
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { registerPlugin } from
|
|
2
|
-
const NativeGeocoder = registerPlugin(
|
|
3
|
-
web: () => import(
|
|
1
|
+
import { registerPlugin } from '@capacitor/core';
|
|
2
|
+
const NativeGeocoder = registerPlugin('NativeGeocoder', {
|
|
3
|
+
web: () => import('./web').then((m) => new m.NativeGeocoderWeb()),
|
|
4
4
|
});
|
|
5
|
-
export * from
|
|
5
|
+
export * from './definitions';
|
|
6
6
|
export { NativeGeocoder };
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,cAAc,GAAG,cAAc,CAAuB,gBAAgB,EAAE;IAC5E,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;CAClE,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,CAAC","sourcesContent":["import { registerPlugin } from
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,cAAc,GAAG,cAAc,CAAuB,gBAAgB,EAAE;IAC5E,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;CAClE,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { NativeGeocoderPlugin } from './definitions';\n\nconst NativeGeocoder = registerPlugin<NativeGeocoderPlugin>('NativeGeocoder', {\n web: () => import('./web').then((m) => new m.NativeGeocoderWeb()),\n});\n\nexport * from './definitions';\nexport { NativeGeocoder };\n"]}
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { WebPlugin } from
|
|
2
|
-
import type { NativeGeocoderPlugin, ReverseOptions, ForwardOptions, Address } from
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { NativeGeocoderPlugin, ReverseOptions, ForwardOptions, Address } from './definitions';
|
|
3
3
|
export declare class NativeGeocoderWeb extends WebPlugin implements NativeGeocoderPlugin {
|
|
4
4
|
reverseGeocode(options: ReverseOptions): Promise<{
|
|
5
5
|
addresses: Address[];
|
package/dist/esm/web.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { WebPlugin } from
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
2
|
const findAC = (address_components, type) => {
|
|
3
3
|
return (address_components.find((component) => component.types.includes(type)) || {
|
|
4
|
-
long_name:
|
|
5
|
-
short_name:
|
|
4
|
+
long_name: '',
|
|
5
|
+
short_name: '',
|
|
6
6
|
types: [],
|
|
7
7
|
});
|
|
8
8
|
};
|
|
9
9
|
export class NativeGeocoderWeb extends WebPlugin {
|
|
10
10
|
async reverseGeocode(options) {
|
|
11
11
|
if (!options.apiKey) {
|
|
12
|
-
throw new Error(
|
|
12
|
+
throw new Error('apiKey is required for web');
|
|
13
13
|
}
|
|
14
|
-
const params = Object.assign(Object.assign({ latlng: `${options.latitude},${options.longitude}`, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: options.resultType ||
|
|
14
|
+
const params = Object.assign(Object.assign({ latlng: `${options.latitude},${options.longitude}`, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: options.resultType || 'street_address' });
|
|
15
15
|
return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)
|
|
16
16
|
.then((response) => response.json())
|
|
17
17
|
.then((data) => {
|
|
@@ -23,21 +23,15 @@ export class NativeGeocoderWeb extends WebPlugin {
|
|
|
23
23
|
return {
|
|
24
24
|
latitude: result.geometry.location.lat,
|
|
25
25
|
longitude: result.geometry.location.lng,
|
|
26
|
-
countryCode: findAC(result.address_components,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
.long_name,
|
|
36
|
-
subLocality: findAC(result.address_components, "sublocality")
|
|
37
|
-
.long_name,
|
|
38
|
-
thoroughfare: findAC(result.address_components, "route")
|
|
39
|
-
.long_name,
|
|
40
|
-
subThoroughfare: findAC(result.address_components, "street_number").long_name,
|
|
26
|
+
countryCode: findAC(result.address_components, 'country').short_name,
|
|
27
|
+
countryName: findAC(result.address_components, 'country').long_name,
|
|
28
|
+
postalCode: findAC(result.address_components, 'postal_code').long_name,
|
|
29
|
+
administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,
|
|
30
|
+
subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,
|
|
31
|
+
locality: findAC(result.address_components, 'locality').long_name,
|
|
32
|
+
subLocality: findAC(result.address_components, 'sublocality').long_name,
|
|
33
|
+
thoroughfare: findAC(result.address_components, 'route').long_name,
|
|
34
|
+
subThoroughfare: findAC(result.address_components, 'street_number').long_name,
|
|
41
35
|
areasOfInterest: [],
|
|
42
36
|
};
|
|
43
37
|
})
|
|
@@ -47,9 +41,9 @@ export class NativeGeocoderWeb extends WebPlugin {
|
|
|
47
41
|
}
|
|
48
42
|
async forwardGeocode(options) {
|
|
49
43
|
if (!options.apiKey) {
|
|
50
|
-
throw new Error(
|
|
44
|
+
throw new Error('apiKey is required for web');
|
|
51
45
|
}
|
|
52
|
-
const params = Object.assign(Object.assign({ address: options.addressString, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type:
|
|
46
|
+
const params = Object.assign(Object.assign({ address: options.addressString, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: 'street_address' });
|
|
53
47
|
return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)
|
|
54
48
|
.then((response) => response.json())
|
|
55
49
|
.then((data) => {
|
|
@@ -61,21 +55,15 @@ export class NativeGeocoderWeb extends WebPlugin {
|
|
|
61
55
|
return {
|
|
62
56
|
latitude: result.geometry.location.lat,
|
|
63
57
|
longitude: result.geometry.location.lng,
|
|
64
|
-
countryCode: findAC(result.address_components,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
.long_name,
|
|
74
|
-
subLocality: findAC(result.address_components, "sublocality")
|
|
75
|
-
.long_name,
|
|
76
|
-
thoroughfare: findAC(result.address_components, "route")
|
|
77
|
-
.long_name,
|
|
78
|
-
subThoroughfare: findAC(result.address_components, "street_number").long_name,
|
|
58
|
+
countryCode: findAC(result.address_components, 'country').short_name,
|
|
59
|
+
countryName: findAC(result.address_components, 'country').long_name,
|
|
60
|
+
postalCode: findAC(result.address_components, 'postal_code').long_name,
|
|
61
|
+
administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,
|
|
62
|
+
subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,
|
|
63
|
+
locality: findAC(result.address_components, 'locality').long_name,
|
|
64
|
+
subLocality: findAC(result.address_components, 'sublocality').long_name,
|
|
65
|
+
thoroughfare: findAC(result.address_components, 'route').long_name,
|
|
66
|
+
subThoroughfare: findAC(result.address_components, 'street_number').long_name,
|
|
79
67
|
areasOfInterest: [],
|
|
80
68
|
};
|
|
81
69
|
})
|
package/dist/esm/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAsC5C,MAAM,MAAM,GAAG,CAAC,kBAAsC,EAAE,IAAY,EAAoB,EAAE;IACxF,OAAO,CACL,kBAAkB,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI;QACxE,SAAS,EAAE,EAAE;QACb,UAAU,EAAE,EAAE;QACd,KAAK,EAAE,EAAE;KACV,CACF,CAAC;AACJ,CAAC,CAAC;AACF,MAAM,OAAO,iBAAkB,SAAQ,SAAS;IAC9C,KAAK,CAAC,cAAc,CAAC,OAAuB;QAC1C,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CA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AAC,GAAG;wBACtC,SAAS,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG;wBACvC,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC,UAAU;wBACpE,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC,SAAS;wBACnE,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,aAAa,CAAC,CAAC,SAAS;wBACtE,kBAAkB,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,6BAA6B,CAAC,CAAC,SAAS;wBAC9F,qBAAqB,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,6BAA6B,CAAC,CAAC,SAAS;wBACjG,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,UAAU,CAAC,CAAC,SAAS;wBACjE,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,aAAa,CAAC,CAAC,SAAS;wBACvE,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC,SAAS;wBAClE,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC,SAAS;wBAC7E,eAAe,EAAE,EAAE;qBACpB,CAAC;gBACJ,CAAC,CAAC;qBACD,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC;aACrC,CAAC;QACJ,CAAC,CAAC,CAAC;IACP,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { NativeGeocoderPlugin, ReverseOptions, ForwardOptions, Address } from './definitions';\n\ninterface AddressComponent {\n long_name: string;\n short_name: string;\n types: string[];\n}\ninterface GeocoderResult {\n address_components: AddressComponent[];\n formatted_address: string;\n geometry: {\n location: {\n lat: number;\n lng: number;\n };\n location_type: string;\n viewport: {\n northeast: {\n lat: number;\n lng: number;\n };\n southwest: {\n lat: number;\n lng: number;\n };\n };\n };\n}\ninterface GeocoderPayload {\n plus_code: {\n compound_code: string;\n global_code: string;\n };\n results: GeocoderResult[];\n}\n\nconst findAC = (address_components: AddressComponent[], type: string): AddressComponent => {\n return (\n address_components.find((component) => component.types.includes(type)) || {\n long_name: '',\n short_name: '',\n types: [],\n }\n );\n};\nexport class NativeGeocoderWeb extends WebPlugin implements NativeGeocoderPlugin {\n async reverseGeocode(options: ReverseOptions): Promise<{ addresses: Address[] }> {\n if (!options.apiKey) {\n throw new Error('apiKey is required for web');\n }\n const params = {\n latlng: `${options.latitude},${options.longitude}`,\n key: options.apiKey,\n ...(options.defaultLocale && { language: options.defaultLocale }),\n result_type: options.resultType || 'street_address',\n };\n return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)\n .then((response) => response.json())\n .then((data: GeocoderPayload): { addresses: Address[] } => {\n return {\n addresses: data.results\n .map((result: GeocoderResult): Address => {\n // transform the response in Address[]\n // use the result from google geocoder and transform it in Address\n\n return {\n latitude: result.geometry.location.lat,\n longitude: result.geometry.location.lng,\n countryCode: findAC(result.address_components, 'country').short_name,\n countryName: findAC(result.address_components, 'country').long_name,\n postalCode: findAC(result.address_components, 'postal_code').long_name,\n administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,\n subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,\n locality: findAC(result.address_components, 'locality').long_name,\n subLocality: findAC(result.address_components, 'sublocality').long_name,\n thoroughfare: findAC(result.address_components, 'route').long_name,\n subThoroughfare: findAC(result.address_components, 'street_number').long_name,\n areasOfInterest: [],\n };\n })\n .slice(0, options.maxResults || 1),\n };\n });\n }\n async forwardGeocode(options: ForwardOptions): Promise<{ addresses: Address[] }> {\n if (!options.apiKey) {\n throw new Error('apiKey is required for web');\n }\n const params = {\n address: options.addressString,\n key: options.apiKey,\n ...(options.defaultLocale && { language: options.defaultLocale }),\n result_type: 'street_address',\n };\n return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)\n .then((response) => response.json())\n .then((data: GeocoderPayload): { addresses: Address[] } => {\n return {\n addresses: data.results\n .map((result: GeocoderResult): Address => {\n // transform the response in Address[]\n // use the result from google geocoder and transform it in Address\n return {\n latitude: result.geometry.location.lat,\n longitude: result.geometry.location.lng,\n countryCode: findAC(result.address_components, 'country').short_name,\n countryName: findAC(result.address_components, 'country').long_name,\n postalCode: findAC(result.address_components, 'postal_code').long_name,\n administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,\n subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,\n locality: findAC(result.address_components, 'locality').long_name,\n subLocality: findAC(result.address_components, 'sublocality').long_name,\n thoroughfare: findAC(result.address_components, 'route').long_name,\n subThoroughfare: findAC(result.address_components, 'street_number').long_name,\n areasOfInterest: [],\n };\n })\n .slice(0, options.maxResults || 1),\n };\n });\n }\n}\n"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -2,23 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
var core = require('@capacitor/core');
|
|
4
4
|
|
|
5
|
-
const NativeGeocoder = core.registerPlugin(
|
|
5
|
+
const NativeGeocoder = core.registerPlugin('NativeGeocoder', {
|
|
6
6
|
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.NativeGeocoderWeb()),
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
const findAC = (address_components, type) => {
|
|
10
10
|
return (address_components.find((component) => component.types.includes(type)) || {
|
|
11
|
-
long_name:
|
|
12
|
-
short_name:
|
|
11
|
+
long_name: '',
|
|
12
|
+
short_name: '',
|
|
13
13
|
types: [],
|
|
14
14
|
});
|
|
15
15
|
};
|
|
16
16
|
class NativeGeocoderWeb extends core.WebPlugin {
|
|
17
17
|
async reverseGeocode(options) {
|
|
18
18
|
if (!options.apiKey) {
|
|
19
|
-
throw new Error(
|
|
19
|
+
throw new Error('apiKey is required for web');
|
|
20
20
|
}
|
|
21
|
-
const params = Object.assign(Object.assign({ latlng: `${options.latitude},${options.longitude}`, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: options.resultType ||
|
|
21
|
+
const params = Object.assign(Object.assign({ latlng: `${options.latitude},${options.longitude}`, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: options.resultType || 'street_address' });
|
|
22
22
|
return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)
|
|
23
23
|
.then((response) => response.json())
|
|
24
24
|
.then((data) => {
|
|
@@ -30,21 +30,15 @@ class NativeGeocoderWeb extends core.WebPlugin {
|
|
|
30
30
|
return {
|
|
31
31
|
latitude: result.geometry.location.lat,
|
|
32
32
|
longitude: result.geometry.location.lng,
|
|
33
|
-
countryCode: findAC(result.address_components,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
.long_name,
|
|
43
|
-
subLocality: findAC(result.address_components, "sublocality")
|
|
44
|
-
.long_name,
|
|
45
|
-
thoroughfare: findAC(result.address_components, "route")
|
|
46
|
-
.long_name,
|
|
47
|
-
subThoroughfare: findAC(result.address_components, "street_number").long_name,
|
|
33
|
+
countryCode: findAC(result.address_components, 'country').short_name,
|
|
34
|
+
countryName: findAC(result.address_components, 'country').long_name,
|
|
35
|
+
postalCode: findAC(result.address_components, 'postal_code').long_name,
|
|
36
|
+
administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,
|
|
37
|
+
subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,
|
|
38
|
+
locality: findAC(result.address_components, 'locality').long_name,
|
|
39
|
+
subLocality: findAC(result.address_components, 'sublocality').long_name,
|
|
40
|
+
thoroughfare: findAC(result.address_components, 'route').long_name,
|
|
41
|
+
subThoroughfare: findAC(result.address_components, 'street_number').long_name,
|
|
48
42
|
areasOfInterest: [],
|
|
49
43
|
};
|
|
50
44
|
})
|
|
@@ -54,9 +48,9 @@ class NativeGeocoderWeb extends core.WebPlugin {
|
|
|
54
48
|
}
|
|
55
49
|
async forwardGeocode(options) {
|
|
56
50
|
if (!options.apiKey) {
|
|
57
|
-
throw new Error(
|
|
51
|
+
throw new Error('apiKey is required for web');
|
|
58
52
|
}
|
|
59
|
-
const params = Object.assign(Object.assign({ address: options.addressString, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type:
|
|
53
|
+
const params = Object.assign(Object.assign({ address: options.addressString, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: 'street_address' });
|
|
60
54
|
return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)
|
|
61
55
|
.then((response) => response.json())
|
|
62
56
|
.then((data) => {
|
|
@@ -68,21 +62,15 @@ class NativeGeocoderWeb extends core.WebPlugin {
|
|
|
68
62
|
return {
|
|
69
63
|
latitude: result.geometry.location.lat,
|
|
70
64
|
longitude: result.geometry.location.lng,
|
|
71
|
-
countryCode: findAC(result.address_components,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
.long_name,
|
|
81
|
-
subLocality: findAC(result.address_components, "sublocality")
|
|
82
|
-
.long_name,
|
|
83
|
-
thoroughfare: findAC(result.address_components, "route")
|
|
84
|
-
.long_name,
|
|
85
|
-
subThoroughfare: findAC(result.address_components, "street_number").long_name,
|
|
65
|
+
countryCode: findAC(result.address_components, 'country').short_name,
|
|
66
|
+
countryName: findAC(result.address_components, 'country').long_name,
|
|
67
|
+
postalCode: findAC(result.address_components, 'postal_code').long_name,
|
|
68
|
+
administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,
|
|
69
|
+
subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,
|
|
70
|
+
locality: findAC(result.address_components, 'locality').long_name,
|
|
71
|
+
subLocality: findAC(result.address_components, 'sublocality').long_name,
|
|
72
|
+
thoroughfare: findAC(result.address_components, 'route').long_name,
|
|
73
|
+
subThoroughfare: findAC(result.address_components, 'street_number').long_name,
|
|
86
74
|
areasOfInterest: [],
|
|
87
75
|
};
|
|
88
76
|
})
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst NativeGeocoder = registerPlugin('NativeGeocoder', {\n web: () => import('./web').then((m) => new m.NativeGeocoderWeb()),\n});\nexport * from './definitions';\nexport { NativeGeocoder };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nconst findAC = (address_components, type) => {\n return (address_components.find((component) => component.types.includes(type)) || {\n long_name: '',\n short_name: '',\n types: [],\n });\n};\nexport class NativeGeocoderWeb extends WebPlugin {\n async reverseGeocode(options) {\n if (!options.apiKey) {\n throw new Error('apiKey is required for web');\n }\n const params = Object.assign(Object.assign({ latlng: `${options.latitude},${options.longitude}`, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: options.resultType || 'street_address' });\n return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)\n .then((response) => response.json())\n .then((data) => {\n return {\n addresses: data.results\n .map((result) => {\n // transform the response in Address[]\n // use the result from google geocoder and transform it in Address\n return {\n latitude: result.geometry.location.lat,\n longitude: result.geometry.location.lng,\n countryCode: findAC(result.address_components, 'country').short_name,\n countryName: findAC(result.address_components, 'country').long_name,\n postalCode: findAC(result.address_components, 'postal_code').long_name,\n administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,\n subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,\n locality: findAC(result.address_components, 'locality').long_name,\n subLocality: findAC(result.address_components, 'sublocality').long_name,\n thoroughfare: findAC(result.address_components, 'route').long_name,\n subThoroughfare: findAC(result.address_components, 'street_number').long_name,\n areasOfInterest: [],\n };\n })\n .slice(0, options.maxResults || 1),\n };\n });\n }\n async forwardGeocode(options) {\n if (!options.apiKey) {\n throw new Error('apiKey is required for web');\n }\n const params = Object.assign(Object.assign({ address: options.addressString, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: 'street_address' });\n return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)\n .then((response) => response.json())\n .then((data) => {\n return {\n addresses: data.results\n .map((result) => {\n // transform the response in Address[]\n // use the result from google geocoder and transform it in Address\n return {\n latitude: result.geometry.location.lat,\n longitude: result.geometry.location.lng,\n countryCode: findAC(result.address_components, 'country').short_name,\n countryName: findAC(result.address_components, 'country').long_name,\n postalCode: findAC(result.address_components, 'postal_code').long_name,\n administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,\n subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,\n locality: findAC(result.address_components, 'locality').long_name,\n subLocality: findAC(result.address_components, 'sublocality').long_name,\n thoroughfare: findAC(result.address_components, 'route').long_name,\n subThoroughfare: findAC(result.address_components, 'street_number').long_name,\n areasOfInterest: [],\n };\n })\n .slice(0, options.maxResults || 1),\n };\n });\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,cAAc,GAAGA,mBAAc,CAAC,gBAAgB,EAAE;AACxD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;AACrE,CAAC;;ACFD,MAAM,MAAM,GAAG,CAAC,kBAAkB,EAAE,IAAI,KAAK;AAC7C,IAAI,QAAQ,kBAAkB,CAAC,I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AQ,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,UAAU,CAAC,CAAC,SAAS;AACzF,wBAAwB,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,aAAa,CAAC,CAAC,SAAS;AAC/F,wBAAwB,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC,SAAS;AAC1F,wBAAwB,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC,SAAS;AACrG,wBAAwB,eAAe,EAAE,EAAE;AAC3C,qBAAqB;AACrB,gBAAgB,CAAC;AACjB,qBAAqB,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC;AACtD,aAAa;AACb,QAAQ,CAAC,CAAC;AACV,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
var capacitorNativeGeocoder = (function (exports, core) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
const NativeGeocoder = core.registerPlugin(
|
|
4
|
+
const NativeGeocoder = core.registerPlugin('NativeGeocoder', {
|
|
5
5
|
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.NativeGeocoderWeb()),
|
|
6
6
|
});
|
|
7
7
|
|
|
8
8
|
const findAC = (address_components, type) => {
|
|
9
9
|
return (address_components.find((component) => component.types.includes(type)) || {
|
|
10
|
-
long_name:
|
|
11
|
-
short_name:
|
|
10
|
+
long_name: '',
|
|
11
|
+
short_name: '',
|
|
12
12
|
types: [],
|
|
13
13
|
});
|
|
14
14
|
};
|
|
15
15
|
class NativeGeocoderWeb extends core.WebPlugin {
|
|
16
16
|
async reverseGeocode(options) {
|
|
17
17
|
if (!options.apiKey) {
|
|
18
|
-
throw new Error(
|
|
18
|
+
throw new Error('apiKey is required for web');
|
|
19
19
|
}
|
|
20
|
-
const params = Object.assign(Object.assign({ latlng: `${options.latitude},${options.longitude}`, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: options.resultType ||
|
|
20
|
+
const params = Object.assign(Object.assign({ latlng: `${options.latitude},${options.longitude}`, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: options.resultType || 'street_address' });
|
|
21
21
|
return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)
|
|
22
22
|
.then((response) => response.json())
|
|
23
23
|
.then((data) => {
|
|
@@ -29,21 +29,15 @@ var capacitorNativeGeocoder = (function (exports, core) {
|
|
|
29
29
|
return {
|
|
30
30
|
latitude: result.geometry.location.lat,
|
|
31
31
|
longitude: result.geometry.location.lng,
|
|
32
|
-
countryCode: findAC(result.address_components,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
.long_name,
|
|
42
|
-
subLocality: findAC(result.address_components, "sublocality")
|
|
43
|
-
.long_name,
|
|
44
|
-
thoroughfare: findAC(result.address_components, "route")
|
|
45
|
-
.long_name,
|
|
46
|
-
subThoroughfare: findAC(result.address_components, "street_number").long_name,
|
|
32
|
+
countryCode: findAC(result.address_components, 'country').short_name,
|
|
33
|
+
countryName: findAC(result.address_components, 'country').long_name,
|
|
34
|
+
postalCode: findAC(result.address_components, 'postal_code').long_name,
|
|
35
|
+
administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,
|
|
36
|
+
subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,
|
|
37
|
+
locality: findAC(result.address_components, 'locality').long_name,
|
|
38
|
+
subLocality: findAC(result.address_components, 'sublocality').long_name,
|
|
39
|
+
thoroughfare: findAC(result.address_components, 'route').long_name,
|
|
40
|
+
subThoroughfare: findAC(result.address_components, 'street_number').long_name,
|
|
47
41
|
areasOfInterest: [],
|
|
48
42
|
};
|
|
49
43
|
})
|
|
@@ -53,9 +47,9 @@ var capacitorNativeGeocoder = (function (exports, core) {
|
|
|
53
47
|
}
|
|
54
48
|
async forwardGeocode(options) {
|
|
55
49
|
if (!options.apiKey) {
|
|
56
|
-
throw new Error(
|
|
50
|
+
throw new Error('apiKey is required for web');
|
|
57
51
|
}
|
|
58
|
-
const params = Object.assign(Object.assign({ address: options.addressString, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type:
|
|
52
|
+
const params = Object.assign(Object.assign({ address: options.addressString, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: 'street_address' });
|
|
59
53
|
return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)
|
|
60
54
|
.then((response) => response.json())
|
|
61
55
|
.then((data) => {
|
|
@@ -67,21 +61,15 @@ var capacitorNativeGeocoder = (function (exports, core) {
|
|
|
67
61
|
return {
|
|
68
62
|
latitude: result.geometry.location.lat,
|
|
69
63
|
longitude: result.geometry.location.lng,
|
|
70
|
-
countryCode: findAC(result.address_components,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
.long_name,
|
|
80
|
-
subLocality: findAC(result.address_components, "sublocality")
|
|
81
|
-
.long_name,
|
|
82
|
-
thoroughfare: findAC(result.address_components, "route")
|
|
83
|
-
.long_name,
|
|
84
|
-
subThoroughfare: findAC(result.address_components, "street_number").long_name,
|
|
64
|
+
countryCode: findAC(result.address_components, 'country').short_name,
|
|
65
|
+
countryName: findAC(result.address_components, 'country').long_name,
|
|
66
|
+
postalCode: findAC(result.address_components, 'postal_code').long_name,
|
|
67
|
+
administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,
|
|
68
|
+
subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,
|
|
69
|
+
locality: findAC(result.address_components, 'locality').long_name,
|
|
70
|
+
subLocality: findAC(result.address_components, 'sublocality').long_name,
|
|
71
|
+
thoroughfare: findAC(result.address_components, 'route').long_name,
|
|
72
|
+
subThoroughfare: findAC(result.address_components, 'street_number').long_name,
|
|
85
73
|
areasOfInterest: [],
|
|
86
74
|
};
|
|
87
75
|
})
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst NativeGeocoder = registerPlugin('NativeGeocoder', {\n web: () => import('./web').then((m) => new m.NativeGeocoderWeb()),\n});\nexport * from './definitions';\nexport { NativeGeocoder };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nconst findAC = (address_components, type) => {\n return (address_components.find((component) => component.types.includes(type)) || {\n long_name: '',\n short_name: '',\n types: [],\n });\n};\nexport class NativeGeocoderWeb extends WebPlugin {\n async reverseGeocode(options) {\n if (!options.apiKey) {\n throw new Error('apiKey is required for web');\n }\n const params = Object.assign(Object.assign({ latlng: `${options.latitude},${options.longitude}`, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: options.resultType || 'street_address' });\n return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)\n .then((response) => response.json())\n .then((data) => {\n return {\n addresses: data.results\n .map((result) => {\n // transform the response in Address[]\n // use the result from google geocoder and transform it in Address\n return {\n latitude: result.geometry.location.lat,\n longitude: result.geometry.location.lng,\n countryCode: findAC(result.address_components, 'country').short_name,\n countryName: findAC(result.address_components, 'country').long_name,\n postalCode: findAC(result.address_components, 'postal_code').long_name,\n administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,\n subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,\n locality: findAC(result.address_components, 'locality').long_name,\n subLocality: findAC(result.address_components, 'sublocality').long_name,\n thoroughfare: findAC(result.address_components, 'route').long_name,\n subThoroughfare: findAC(result.address_components, 'street_number').long_name,\n areasOfInterest: [],\n };\n })\n .slice(0, options.maxResults || 1),\n };\n });\n }\n async forwardGeocode(options) {\n if (!options.apiKey) {\n throw new Error('apiKey is required for web');\n }\n const params = Object.assign(Object.assign({ address: options.addressString, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: 'street_address' });\n return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)\n .then((response) => response.json())\n .then((data) => {\n return {\n addresses: data.results\n .map((result) => {\n // transform the response in Address[]\n // use the result from google geocoder and transform it in Address\n return {\n latitude: result.geometry.location.lat,\n longitude: result.geometry.location.lng,\n countryCode: findAC(result.address_components, 'country').short_name,\n countryName: findAC(result.address_components, 'country').long_name,\n postalCode: findAC(result.address_components, 'postal_code').long_name,\n administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,\n subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,\n locality: findAC(result.address_components, 'locality').long_name,\n subLocality: findAC(result.address_components, 'sublocality').long_name,\n thoroughfare: findAC(result.address_components, 'route').long_name,\n subThoroughfare: findAC(result.address_components, 'street_number').long_name,\n areasOfInterest: [],\n };\n })\n .slice(0, options.maxResults || 1),\n };\n });\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,cAAc,GAAGA,mBAAc,CAAC,gBAAgB,EAAE;IACxD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;IACrE,CAAC;;ICFD,MAAM,MAAM,GAAG,CAAC,kBAAkB,EAAE,IAAI,KAAK;IAC7C,IAAI,QAAQ,kBAAkB,CAAC,IAAI,CAAC,CAAC,SAAS,KAAK,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC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F,wBAAwB,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,aAAa,CAAC,CAAC,SAAS;IAC/F,wBAAwB,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC,SAAS;IAC1F,wBAAwB,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC,SAAS;IACrG,wBAAwB,eAAe,EAAE,EAAE;IAC3C,qBAAqB;IACrB,gBAAgB,CAAC;IACjB,qBAAqB,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC;IACtD,aAAa;IACb,QAAQ,CAAC,CAAC;IACV,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/nativegeocoder",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.10",
|
|
4
4
|
"description": "Capacitor plugin for native forward and reverse geocoding",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
40
40
|
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --autocorrect --format",
|
|
41
41
|
"eslint": "eslint .",
|
|
42
|
-
"prettier": "prettier
|
|
42
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
|
|
43
43
|
"swiftlint": "node-swiftlint",
|
|
44
44
|
"docgen": "docgen --api NativeGeocoderPlugin --output-readme README.md --output-json dist/docs.json",
|
|
45
45
|
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|