@capgo/nativegeocoder 0.1.62 → 1.0.3
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/build.gradle +10 -9
- package/android/src/main/AndroidManifest.xml +1 -1
- package/android/src/main/java/ee/forgr/capacitor_nativegeocoder/NativeGeocoder.java +299 -198
- 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 +37 -25
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +37 -25
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +37 -25
- package/dist/plugin.js.map +1 -1
- package/package.json +21 -21
package/android/build.gradle
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
ext {
|
|
2
|
-
junitVersion =
|
|
3
|
-
androidxJunitVersion =
|
|
4
|
-
androidxEspressoCoreVersion =
|
|
5
|
-
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
|
|
4
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
|
|
5
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
buildscript {
|
|
@@ -11,17 +11,18 @@ buildscript {
|
|
|
11
11
|
google()
|
|
12
12
|
}
|
|
13
13
|
dependencies {
|
|
14
|
-
classpath 'com.android.tools.build:gradle:
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.0.0'
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
apply plugin: 'com.android.library'
|
|
19
19
|
|
|
20
20
|
android {
|
|
21
|
-
|
|
21
|
+
namespace "ee.forgr.capacitor_nativegeocoder"
|
|
22
|
+
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 33
|
|
22
23
|
defaultConfig {
|
|
23
24
|
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
|
|
24
|
-
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion :
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 33
|
|
25
26
|
versionCode 1
|
|
26
27
|
versionName "1.0"
|
|
27
28
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
@@ -36,8 +37,8 @@ android {
|
|
|
36
37
|
abortOnError false
|
|
37
38
|
}
|
|
38
39
|
compileOptions {
|
|
39
|
-
sourceCompatibility JavaVersion.
|
|
40
|
-
targetCompatibility JavaVersion.
|
|
40
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
41
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
|
|
@@ -15,224 +15,325 @@ 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
|
-
|
|
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
|
-
}
|
|
25
|
+
private Geocoder geocoder;
|
|
26
|
+
public Context context;
|
|
39
27
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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(
|
|
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
|
+
}
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
}
|
|
44
|
+
if (!Geocoder.isPresent()) {
|
|
45
|
+
call.reject("Geocoder is not present on this device/emulator.");
|
|
46
|
+
return;
|
|
90
47
|
}
|
|
91
48
|
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
}
|
|
49
|
+
NativeGeocoderOptions geocoderOptions = getNativeGeocoderOptions(call);
|
|
50
|
+
geocoder = createGeocoderWithOptions(geocoderOptions);
|
|
102
51
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
52
|
+
try {
|
|
53
|
+
List<Address> geoResults = geocoder.getFromLocation(
|
|
54
|
+
latitude,
|
|
55
|
+
longitude,
|
|
56
|
+
geocoderOptions.maxResults
|
|
57
|
+
);
|
|
58
|
+
if (geoResults.size() > 0) {
|
|
59
|
+
int maxResultObjects = geoResults.size() >= geocoderOptions.maxResults
|
|
60
|
+
? geoResults.size()
|
|
61
|
+
: geoResults.size();
|
|
62
|
+
JSONArray resultObj = new JSONArray();
|
|
107
63
|
|
|
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
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
+
);
|
|
125
|
+
|
|
126
|
+
resultObj.put(placemark);
|
|
169
127
|
}
|
|
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);
|
|
170
140
|
}
|
|
141
|
+
}
|
|
171
142
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
143
|
+
/**
|
|
144
|
+
* Forward geocode a given address to find coordinates
|
|
145
|
+
* @param addressString String
|
|
146
|
+
* @param call PluginCall
|
|
147
|
+
*/
|
|
148
|
+
public void forwardGeocode(String addressString, PluginCall call) {
|
|
149
|
+
if (addressString == null || addressString.length() == 0) {
|
|
150
|
+
call.reject("Expected a non-empty string argument.");
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (!Geocoder.isPresent()) {
|
|
155
|
+
call.reject("Geocoder is not present on this device/emulator.");
|
|
156
|
+
return;
|
|
183
157
|
}
|
|
184
158
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
159
|
+
NativeGeocoderOptions geocoderOptions = getNativeGeocoderOptions(call);
|
|
160
|
+
geocoder = createGeocoderWithOptions(geocoderOptions);
|
|
161
|
+
|
|
162
|
+
try {
|
|
163
|
+
List<Address> geoResults = geocoder.getFromLocationName(
|
|
164
|
+
addressString,
|
|
165
|
+
geocoderOptions.maxResults
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
if (geoResults.size() > 0) {
|
|
169
|
+
int maxResultObjects = geoResults.size() >= geocoderOptions.maxResults
|
|
170
|
+
? geoResults.size()
|
|
171
|
+
: geoResults.size();
|
|
172
|
+
JSONArray resultObj = new JSONArray();
|
|
173
|
+
|
|
174
|
+
for (int i = 0; i < maxResultObjects; i++) {
|
|
175
|
+
Address address = geoResults.get(i);
|
|
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);
|
|
202
236
|
}
|
|
237
|
+
} catch (RuntimeException e) {
|
|
238
|
+
e.printStackTrace();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (resultObj.length() == 0) {
|
|
243
|
+
call.reject("Cannot get latitude and/or longitude.");
|
|
203
244
|
} else {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
245
|
+
JSObject ret = new JSObject();
|
|
246
|
+
ret.put("addresses", resultObj);
|
|
247
|
+
call.resolve(ret);
|
|
207
248
|
}
|
|
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
|
+
}
|
|
208
260
|
|
|
209
|
-
|
|
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();
|
|
210
273
|
}
|
|
274
|
+
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
|
|
275
|
+
}
|
|
211
276
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
277
|
+
/**
|
|
278
|
+
* Get a valid NativeGeocoderOptions object
|
|
279
|
+
* @param options JSONObject
|
|
280
|
+
* @return NativeGeocoderOptions
|
|
281
|
+
*/
|
|
282
|
+
private NativeGeocoderOptions getNativeGeocoderOptions(PluginCall options) {
|
|
283
|
+
NativeGeocoderOptions geocoderOptions = new NativeGeocoderOptions();
|
|
284
|
+
|
|
285
|
+
if (options != null) {
|
|
286
|
+
geocoderOptions.useLocale = options.getBoolean("useLocale", false);
|
|
287
|
+
geocoderOptions.defaultLocale = options.getString("defaultLocale", null);
|
|
288
|
+
geocoderOptions.maxResults = options.getInt("maxResults", 1);
|
|
289
|
+
if (geocoderOptions.maxResults > 0) {
|
|
290
|
+
int MAX_RESULTS_COUNT = 5;
|
|
291
|
+
geocoderOptions.maxResults =
|
|
292
|
+
Math.min(geocoderOptions.maxResults, MAX_RESULTS_COUNT);
|
|
293
|
+
} else {
|
|
294
|
+
geocoderOptions.maxResults = 1;
|
|
295
|
+
}
|
|
296
|
+
} else {
|
|
297
|
+
geocoderOptions.useLocale = true;
|
|
298
|
+
geocoderOptions.defaultLocale = null;
|
|
299
|
+
geocoderOptions.maxResults = 1;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return geocoderOptions;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Create a Geocoder with NativeGeocoderOptions
|
|
307
|
+
* @param geocoderOptions NativeGeocoderOptions
|
|
308
|
+
* @return Geocoder
|
|
309
|
+
*/
|
|
310
|
+
private Geocoder createGeocoderWithOptions(
|
|
311
|
+
NativeGeocoderOptions geocoderOptions
|
|
312
|
+
) {
|
|
313
|
+
if (
|
|
314
|
+
geocoderOptions.defaultLocale != null &&
|
|
315
|
+
!geocoderOptions.defaultLocale.isEmpty()
|
|
316
|
+
) {
|
|
317
|
+
Locale locale;
|
|
318
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
319
|
+
locale = Locale.forLanguageTag(geocoderOptions.defaultLocale);
|
|
320
|
+
} else {
|
|
321
|
+
String[] parts = geocoderOptions.defaultLocale.split("[-_]", -1);
|
|
322
|
+
if (parts.length == 1) locale = new Locale(parts[0]); else if (
|
|
323
|
+
parts.length == 2 || (parts.length == 3 && parts[2].startsWith("#"))
|
|
324
|
+
) locale = new Locale(parts[0], parts[1]); else locale =
|
|
325
|
+
new Locale(parts[0], parts[1], parts[2]);
|
|
326
|
+
}
|
|
327
|
+
geocoder = new Geocoder(context.getApplicationContext(), locale);
|
|
328
|
+
} else {
|
|
329
|
+
if (geocoderOptions.useLocale) {
|
|
330
|
+
geocoder =
|
|
331
|
+
new Geocoder(context.getApplicationContext(), Locale.getDefault());
|
|
332
|
+
} else {
|
|
333
|
+
geocoder =
|
|
334
|
+
new Geocoder(context.getApplicationContext(), Locale.ENGLISH);
|
|
335
|
+
}
|
|
237
336
|
}
|
|
337
|
+
return geocoder;
|
|
338
|
+
}
|
|
238
339
|
}
|
|
@@ -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
|
-
|
|
26
|
-
}
|
|
27
|
-
implementation.reverseGeocode(latitude, longitude, call);
|
|
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;
|
|
28
26
|
}
|
|
27
|
+
implementation.reverseGeocode(latitude, longitude, call);
|
|
28
|
+
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
implementation.forwardGeocode(addressString, call);
|
|
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;
|
|
38
36
|
}
|
|
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, Adress } from
|
|
1
|
+
import { WebPlugin } from "@capacitor/core";
|
|
2
|
+
import type { NativeGeocoderPlugin, reverseOptions, ForwardOptions, Adress } from "./definitions";
|
|
3
3
|
export declare class NativeGeocoderWeb extends WebPlugin implements NativeGeocoderPlugin {
|
|
4
4
|
reverseGeocode(options: reverseOptions): Promise<{
|
|
5
5
|
addresses: Adress[];
|
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:
|
|
14
|
+
const params = Object.assign(Object.assign({ latlng: `${options.latitude},${options.longitude}`, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: "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,15 +23,21 @@ 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
|
-
|
|
26
|
+
countryCode: findAC(result.address_components, "country")
|
|
27
|
+
.short_name,
|
|
28
|
+
countryName: findAC(result.address_components, "country")
|
|
29
|
+
.long_name,
|
|
30
|
+
postalCode: findAC(result.address_components, "postal_code")
|
|
31
|
+
.long_name,
|
|
32
|
+
administrativeArea: findAC(result.address_components, "administrative_area_level_1").long_name,
|
|
33
|
+
subAdministrativeArea: findAC(result.address_components, "administrative_area_level_2").long_name,
|
|
34
|
+
locality: findAC(result.address_components, "locality")
|
|
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,
|
|
35
41
|
areasOfInterest: [],
|
|
36
42
|
};
|
|
37
43
|
})
|
|
@@ -41,9 +47,9 @@ export class NativeGeocoderWeb extends WebPlugin {
|
|
|
41
47
|
}
|
|
42
48
|
async forwardGeocode(options) {
|
|
43
49
|
if (!options.apiKey) {
|
|
44
|
-
throw new Error(
|
|
50
|
+
throw new Error("apiKey is required for web");
|
|
45
51
|
}
|
|
46
|
-
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" });
|
|
47
53
|
return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)
|
|
48
54
|
.then((response) => response.json())
|
|
49
55
|
.then((data) => {
|
|
@@ -55,15 +61,21 @@ export class NativeGeocoderWeb extends WebPlugin {
|
|
|
55
61
|
return {
|
|
56
62
|
latitude: result.geometry.location.lat,
|
|
57
63
|
longitude: result.geometry.location.lng,
|
|
58
|
-
countryCode: findAC(result.address_components,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
countryCode: findAC(result.address_components, "country")
|
|
65
|
+
.short_name,
|
|
66
|
+
countryName: findAC(result.address_components, "country")
|
|
67
|
+
.long_name,
|
|
68
|
+
postalCode: findAC(result.address_components, "postal_code")
|
|
69
|
+
.long_name,
|
|
70
|
+
administrativeArea: findAC(result.address_components, "administrative_area_level_1").long_name,
|
|
71
|
+
subAdministrativeArea: findAC(result.address_components, "administrative_area_level_2").long_name,
|
|
72
|
+
locality: findAC(result.address_components, "locality")
|
|
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,
|
|
67
79
|
areasOfInterest: [],
|
|
68
80
|
};
|
|
69
81
|
})
|
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;AA2C5C,MAAM,MAAM,GAAG,CACb,kBAAsC,EACtC,IAAY,EACM,EAAE;IACpB,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,iBACX,SAAQ,SAAS;IAGjB,KAAK,CAAC,cAAc,CAClB,OAAuB;QAEvB,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YACnB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;SAC/C;QACD,MAAM,MAAM,iCACV,MAAM,EAAE,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,SAAS,EAAE,EAClD,GAAG,EAAE,OAAO,CAAC,MAAM,IAChB,CAAC,OAAO,CAAC,aAAa,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,aAAa,EAAE,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MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,aAAa,CAAC;6BACzD,SAAS;wBACZ,kBAAkB,EAAE,MAAM,CACxB,MAAM,CAAC,kBAAkB,EACzB,6BAA6B,CAC9B,CAAC,SAAS;wBACX,qBAAqB,EAAE,MAAM,CAC3B,MAAM,CAAC,kBAAkB,EACzB,6BAA6B,CAC9B,CAAC,SAAS;wBACX,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,UAAU,CAAC;6BACpD,SAAS;wBACZ,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,aAAa,CAAC;6BAC1D,SAAS;wBACZ,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,OAAO,CAAC;6BACrD,SAAS;wBACZ,eAAe,EAAE,MAAM,CACrB,MAAM,CAAC,kBAAkB,EACzB,eAAe,CAChB,CAAC,SAAS;wBACX,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 {\n NativeGeocoderPlugin,\n reverseOptions,\n ForwardOptions,\n Adress,\n} 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 = (\n address_components: AddressComponent[],\n type: string\n): 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\n extends WebPlugin\n implements NativeGeocoderPlugin\n{\n async reverseGeocode(\n options: reverseOptions\n ): Promise<{ addresses: Adress[] }> {\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: \"street_address\",\n };\n return fetch(\n `https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(\n params\n ).toString()}`\n )\n .then((response) => response.json())\n .then((data: GeocoderPayload): { addresses: Adress[] } => {\n return {\n addresses: data.results\n .map((result: GeocoderResult): Adress => {\n // transform the response in Adress[]\n // use the restul from google geocoder and transform it in Adress\n\n return {\n latitude: result.geometry.location.lat,\n longitude: result.geometry.location.lng,\n countryCode: findAC(result.address_components, \"country\")\n .short_name,\n countryName: findAC(result.address_components, \"country\")\n .long_name,\n postalCode: findAC(result.address_components, \"postal_code\")\n .long_name,\n administrativeArea: findAC(\n result.address_components,\n \"administrative_area_level_1\"\n ).long_name,\n subAdministrativeArea: findAC(\n result.address_components,\n \"administrative_area_level_2\"\n ).long_name,\n locality: findAC(result.address_components, \"locality\")\n .long_name,\n subLocality: findAC(result.address_components, \"sublocality\")\n .long_name,\n thoroughfare: findAC(result.address_components, \"route\")\n .long_name,\n subThoroughfare: findAC(\n result.address_components,\n \"street_number\"\n ).long_name,\n areasOfInterest: [],\n };\n })\n .slice(0, options.maxResults || 1),\n };\n });\n }\n async forwardGeocode(\n options: ForwardOptions\n ): Promise<{ addresses: Adress[] }> {\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(\n `https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(\n params\n ).toString()}`\n )\n .then((response) => response.json())\n .then((data: GeocoderPayload): { addresses: Adress[] } => {\n return {\n addresses: data.results\n .map((result: GeocoderResult): Adress => {\n // transform the response in Adress[]\n // use the restul from google geocoder and transform it in Adress\n return {\n latitude: result.geometry.location.lat,\n longitude: result.geometry.location.lng,\n countryCode: findAC(result.address_components, \"country\")\n .short_name,\n countryName: findAC(result.address_components, \"country\")\n .long_name,\n postalCode: findAC(result.address_components, \"postal_code\")\n .long_name,\n administrativeArea: findAC(\n result.address_components,\n \"administrative_area_level_1\"\n ).long_name,\n subAdministrativeArea: findAC(\n result.address_components,\n \"administrative_area_level_2\"\n ).long_name,\n locality: findAC(result.address_components, \"locality\")\n .long_name,\n subLocality: findAC(result.address_components, \"sublocality\")\n .long_name,\n thoroughfare: findAC(result.address_components, \"route\")\n .long_name,\n subThoroughfare: findAC(\n result.address_components,\n \"street_number\"\n ).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:
|
|
21
|
+
const params = Object.assign(Object.assign({ latlng: `${options.latitude},${options.longitude}`, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: "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,15 +30,21 @@ 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
|
-
|
|
33
|
+
countryCode: findAC(result.address_components, "country")
|
|
34
|
+
.short_name,
|
|
35
|
+
countryName: findAC(result.address_components, "country")
|
|
36
|
+
.long_name,
|
|
37
|
+
postalCode: findAC(result.address_components, "postal_code")
|
|
38
|
+
.long_name,
|
|
39
|
+
administrativeArea: findAC(result.address_components, "administrative_area_level_1").long_name,
|
|
40
|
+
subAdministrativeArea: findAC(result.address_components, "administrative_area_level_2").long_name,
|
|
41
|
+
locality: findAC(result.address_components, "locality")
|
|
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,
|
|
42
48
|
areasOfInterest: [],
|
|
43
49
|
};
|
|
44
50
|
})
|
|
@@ -48,9 +54,9 @@ class NativeGeocoderWeb extends core.WebPlugin {
|
|
|
48
54
|
}
|
|
49
55
|
async forwardGeocode(options) {
|
|
50
56
|
if (!options.apiKey) {
|
|
51
|
-
throw new Error(
|
|
57
|
+
throw new Error("apiKey is required for web");
|
|
52
58
|
}
|
|
53
|
-
const params = Object.assign(Object.assign({ address: options.addressString, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type:
|
|
59
|
+
const params = Object.assign(Object.assign({ address: options.addressString, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: "street_address" });
|
|
54
60
|
return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)
|
|
55
61
|
.then((response) => response.json())
|
|
56
62
|
.then((data) => {
|
|
@@ -62,15 +68,21 @@ class NativeGeocoderWeb extends core.WebPlugin {
|
|
|
62
68
|
return {
|
|
63
69
|
latitude: result.geometry.location.lat,
|
|
64
70
|
longitude: result.geometry.location.lng,
|
|
65
|
-
countryCode: findAC(result.address_components,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
countryCode: findAC(result.address_components, "country")
|
|
72
|
+
.short_name,
|
|
73
|
+
countryName: findAC(result.address_components, "country")
|
|
74
|
+
.long_name,
|
|
75
|
+
postalCode: findAC(result.address_components, "postal_code")
|
|
76
|
+
.long_name,
|
|
77
|
+
administrativeArea: findAC(result.address_components, "administrative_area_level_1").long_name,
|
|
78
|
+
subAdministrativeArea: findAC(result.address_components, "administrative_area_level_2").long_name,
|
|
79
|
+
locality: findAC(result.address_components, "locality")
|
|
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,
|
|
74
86
|
areasOfInterest: [],
|
|
75
87
|
};
|
|
76
88
|
})
|
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: \"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 Adress[]\n // use the restul from google geocoder and transform it in Adress\n return {\n latitude: result.geometry.location.lat,\n longitude: result.geometry.location.lng,\n countryCode: findAC(result.address_components, \"country\")\n .short_name,\n countryName: findAC(result.address_components, \"country\")\n .long_name,\n postalCode: findAC(result.address_components, \"postal_code\")\n .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\")\n .long_name,\n subLocality: findAC(result.address_components, \"sublocality\")\n .long_name,\n thoroughfare: findAC(result.address_components, \"route\")\n .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 Adress[]\n // use the restul from google geocoder and transform it in Adress\n return {\n latitude: result.geometry.location.lat,\n longitude: result.geometry.location.lng,\n countryCode: findAC(result.address_components, \"country\")\n .short_name,\n countryName: findAC(result.address_components, \"country\")\n .long_name,\n postalCode: findAC(result.address_components, \"postal_code\")\n .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\")\n .long_name,\n subLocality: findAC(result.address_components, \"sublocality\")\n .long_name,\n thoroughfare: findAC(result.address_components, \"route\")\n .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,IAAI,CAAC,CAAC,SAAS,KAAK,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI;AACtF,QAAQ,SAAS,EAAE,EAAE;AACrB,QAAQ,UAAU,EAAE,EAAE;AACtB,QAAQ,KAAK,E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AU,CAAC;AAC/E,6BAA6B,SAAS;AACtC,wBAAwB,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,aAAa,CAAC;AACrF,6BAA6B,SAAS;AACtC,wBAAwB,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,OAAO,CAAC;AAChF,6BAA6B,SAAS;AACtC,wBAAwB,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC,SAAS;AACrG,wBAAwB,eAAe,EAAE,EAAE;AAC3C,qBAAqB,CAAC;AACtB,iBAAiB,CAAC;AAClB,qBAAqB,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC;AACtD,aAAa,CAAC;AACd,SAAS,CAAC,CAAC;AACX,KAAK;AACL;;;;;;;;;"}
|
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:
|
|
20
|
+
const params = Object.assign(Object.assign({ latlng: `${options.latitude},${options.longitude}`, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: "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,15 +29,21 @@ 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
|
-
|
|
32
|
+
countryCode: findAC(result.address_components, "country")
|
|
33
|
+
.short_name,
|
|
34
|
+
countryName: findAC(result.address_components, "country")
|
|
35
|
+
.long_name,
|
|
36
|
+
postalCode: findAC(result.address_components, "postal_code")
|
|
37
|
+
.long_name,
|
|
38
|
+
administrativeArea: findAC(result.address_components, "administrative_area_level_1").long_name,
|
|
39
|
+
subAdministrativeArea: findAC(result.address_components, "administrative_area_level_2").long_name,
|
|
40
|
+
locality: findAC(result.address_components, "locality")
|
|
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,
|
|
41
47
|
areasOfInterest: [],
|
|
42
48
|
};
|
|
43
49
|
})
|
|
@@ -47,9 +53,9 @@ var capacitorNativeGeocoder = (function (exports, core) {
|
|
|
47
53
|
}
|
|
48
54
|
async forwardGeocode(options) {
|
|
49
55
|
if (!options.apiKey) {
|
|
50
|
-
throw new Error(
|
|
56
|
+
throw new Error("apiKey is required for web");
|
|
51
57
|
}
|
|
52
|
-
const params = Object.assign(Object.assign({ address: options.addressString, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type:
|
|
58
|
+
const params = Object.assign(Object.assign({ address: options.addressString, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: "street_address" });
|
|
53
59
|
return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)
|
|
54
60
|
.then((response) => response.json())
|
|
55
61
|
.then((data) => {
|
|
@@ -61,15 +67,21 @@ var capacitorNativeGeocoder = (function (exports, core) {
|
|
|
61
67
|
return {
|
|
62
68
|
latitude: result.geometry.location.lat,
|
|
63
69
|
longitude: result.geometry.location.lng,
|
|
64
|
-
countryCode: findAC(result.address_components,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
countryCode: findAC(result.address_components, "country")
|
|
71
|
+
.short_name,
|
|
72
|
+
countryName: findAC(result.address_components, "country")
|
|
73
|
+
.long_name,
|
|
74
|
+
postalCode: findAC(result.address_components, "postal_code")
|
|
75
|
+
.long_name,
|
|
76
|
+
administrativeArea: findAC(result.address_components, "administrative_area_level_1").long_name,
|
|
77
|
+
subAdministrativeArea: findAC(result.address_components, "administrative_area_level_2").long_name,
|
|
78
|
+
locality: findAC(result.address_components, "locality")
|
|
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,
|
|
73
85
|
areasOfInterest: [],
|
|
74
86
|
};
|
|
75
87
|
})
|
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: \"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 Adress[]\n // use the restul from google geocoder and transform it in Adress\n return {\n latitude: result.geometry.location.lat,\n longitude: result.geometry.location.lng,\n countryCode: findAC(result.address_components, \"country\")\n .short_name,\n countryName: findAC(result.address_components, \"country\")\n .long_name,\n postalCode: findAC(result.address_components, \"postal_code\")\n .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\")\n .long_name,\n subLocality: findAC(result.address_components, \"sublocality\")\n .long_name,\n thoroughfare: findAC(result.address_components, \"route\")\n .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 Adress[]\n // use the restul from google geocoder and transform it in Adress\n return {\n latitude: result.geometry.location.lat,\n longitude: result.geometry.location.lng,\n countryCode: findAC(result.address_components, \"country\")\n .short_name,\n countryName: findAC(result.address_components, \"country\")\n .long_name,\n postalCode: findAC(result.address_components, \"postal_code\")\n .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\")\n .long_name,\n subLocality: findAC(result.address_components, \"sublocality\")\n .long_name,\n thoroughfare: findAC(result.address_components, \"route\")\n .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,CAAC,IAAI;IACtF,QAAQ,SAAS,EAAE,EAAE;IACrB,QAAQ,UAAU,EAAE,EAAE;IACtB,QAAQ,KAAK,EAAE,EAAE;IACjB,KAAK,EAAE;IACP,CAAC,CAAC;IACK,M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EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,aAAa,CAAC;IACrF,6BAA6B,SAAS;IACtC,wBAAwB,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,OAAO,CAAC;IAChF,6BAA6B,SAAS;IACtC,wBAAwB,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC,SAAS;IACrG,wBAAwB,eAAe,EAAE,EAAE;IAC3C,qBAAqB,CAAC;IACtB,iBAAiB,CAAC;IAClB,qBAAqB,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC;IACtD,aAAa,CAAC;IACd,SAAS,CAAC,CAAC;IACX,KAAK;IACL;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/nativegeocoder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.3",
|
|
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",
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
36
36
|
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --autocorrect --format",
|
|
37
37
|
"eslint": "eslint . --ext ts",
|
|
38
|
-
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
|
|
38
|
+
"prettier": "prettier --config .prettierrc.js \"**/*.{css,html,ts,js,java}\"",
|
|
39
39
|
"swiftlint": "node-swiftlint",
|
|
40
40
|
"docgen": "docgen --api NativeGeocoderPlugin --output-readme README.md --output-json dist/docs.json",
|
|
41
41
|
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
42
|
-
"clean": "rimraf ./dist
|
|
42
|
+
"clean": "rimraf ./dist",
|
|
43
43
|
"watch": "tsc --watch",
|
|
44
44
|
"prepublishOnly": "npm run build",
|
|
45
45
|
"prepare": "husky install"
|
|
@@ -47,28 +47,28 @@
|
|
|
47
47
|
"author": "Martin Donadieu <martindonadieu@gmail.com>",
|
|
48
48
|
"license": "MIT",
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@capacitor/android": "^
|
|
51
|
-
"@capacitor/cli": "^
|
|
52
|
-
"@capacitor/core": "^
|
|
53
|
-
"@capacitor/docgen": "^0.2.
|
|
54
|
-
"@capacitor/ios": "^
|
|
50
|
+
"@capacitor/android": "^5.0.3",
|
|
51
|
+
"@capacitor/cli": "^5.0.3",
|
|
52
|
+
"@capacitor/core": "^5.0.0",
|
|
53
|
+
"@capacitor/docgen": "^0.2.1",
|
|
54
|
+
"@capacitor/ios": "^5.0.3",
|
|
55
55
|
"@ionic/eslint-config": "^0.3.0",
|
|
56
|
-
"@ionic/prettier-config": "^
|
|
56
|
+
"@ionic/prettier-config": "^3.0.0",
|
|
57
57
|
"@ionic/swiftlint-config": "^1.1.2",
|
|
58
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
59
|
-
"@typescript-eslint/parser": "^5.
|
|
60
|
-
"eslint": "^8.
|
|
61
|
-
"eslint-plugin-import": "^2.
|
|
62
|
-
"husky": "^8.0.
|
|
63
|
-
"prettier": "^2.
|
|
64
|
-
"prettier-plugin-java": "^2.
|
|
65
|
-
"rimraf": "^
|
|
66
|
-
"rollup": "^3.
|
|
67
|
-
"swiftlint": "^1.0.
|
|
68
|
-
"typescript": "^
|
|
58
|
+
"@typescript-eslint/eslint-plugin": "^5.59.6",
|
|
59
|
+
"@typescript-eslint/parser": "^5.59.6",
|
|
60
|
+
"eslint": "^8.41.0",
|
|
61
|
+
"eslint-plugin-import": "^2.27.5",
|
|
62
|
+
"husky": "^8.0.3",
|
|
63
|
+
"prettier": "^2.8.8",
|
|
64
|
+
"prettier-plugin-java": "^2.1.0",
|
|
65
|
+
"rimraf": "^5.0.1",
|
|
66
|
+
"rollup": "^3.23.0",
|
|
67
|
+
"swiftlint": "^1.0.2",
|
|
68
|
+
"typescript": "^5.0.4"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
|
-
"@capacitor/core": "^
|
|
71
|
+
"@capacitor/core": "^5.0.0"
|
|
72
72
|
},
|
|
73
73
|
"prettier": "@ionic/prettier-config",
|
|
74
74
|
"swiftlint": "@ionic/swiftlint-config",
|