@capgo/nativegeocoder 0.1.15 → 0.1.16
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/README.md +1 -1
- package/dist/docs.json +7 -7
- package/dist/esm/definitions.d.ts +1 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.js +45 -38
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +45 -38
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +45 -38
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -96,6 +96,7 @@ Convert an address to latitude and longitude
|
|
|
96
96
|
| **`latitude`** | <code>number</code> |
|
|
97
97
|
| **`longitude`** | <code>number</code> |
|
|
98
98
|
| **`countryCode`** | <code>string</code> |
|
|
99
|
+
| **`countryName`** | <code>string</code> |
|
|
99
100
|
| **`postalCode`** | <code>string</code> |
|
|
100
101
|
| **`administrativeArea`** | <code>string</code> |
|
|
101
102
|
| **`subAdministrativeArea`** | <code>string</code> |
|
|
@@ -104,7 +105,6 @@ Convert an address to latitude and longitude
|
|
|
104
105
|
| **`thoroughfare`** | <code>string</code> |
|
|
105
106
|
| **`subThoroughfare`** | <code>string</code> |
|
|
106
107
|
| **`areasOfInterest`** | <code>string[]</code> |
|
|
107
|
-
| **`formatted_address`** | <code>string</code> |
|
|
108
108
|
|
|
109
109
|
|
|
110
110
|
#### reverseOptions
|
package/dist/docs.json
CHANGED
|
@@ -105,6 +105,13 @@
|
|
|
105
105
|
"complexTypes": [],
|
|
106
106
|
"type": "string"
|
|
107
107
|
},
|
|
108
|
+
{
|
|
109
|
+
"name": "countryName",
|
|
110
|
+
"tags": [],
|
|
111
|
+
"docs": "",
|
|
112
|
+
"complexTypes": [],
|
|
113
|
+
"type": "string"
|
|
114
|
+
},
|
|
108
115
|
{
|
|
109
116
|
"name": "postalCode",
|
|
110
117
|
"tags": [],
|
|
@@ -160,13 +167,6 @@
|
|
|
160
167
|
"docs": "",
|
|
161
168
|
"complexTypes": [],
|
|
162
169
|
"type": "string[]"
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
"name": "formatted_address",
|
|
166
|
-
"tags": [],
|
|
167
|
-
"docs": "",
|
|
168
|
-
"complexTypes": [],
|
|
169
|
-
"type": "string"
|
|
170
170
|
}
|
|
171
171
|
]
|
|
172
172
|
},
|
|
@@ -2,6 +2,7 @@ export interface Adress {
|
|
|
2
2
|
latitude: number;
|
|
3
3
|
longitude: number;
|
|
4
4
|
countryCode: string;
|
|
5
|
+
countryName: string;
|
|
5
6
|
postalCode: string;
|
|
6
7
|
administrativeArea: string;
|
|
7
8
|
subAdministrativeArea: string;
|
|
@@ -10,7 +11,6 @@ export interface Adress {
|
|
|
10
11
|
thoroughfare: string;
|
|
11
12
|
subThoroughfare: string;
|
|
12
13
|
areasOfInterest: string[];
|
|
13
|
-
formatted_address: string;
|
|
14
14
|
}
|
|
15
15
|
export interface ForwardOptions {
|
|
16
16
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface Adress {\n latitude:\tnumber\n longitude:\tnumber\n countryCode:\tstring\n postalCode:\tstring\n administrativeArea:\tstring\n subAdministrativeArea:\tstring\n locality:\tstring\n subLocality:\tstring\n thoroughfare:\tstring\n subThoroughfare:\tstring\n areasOfInterest:\tstring[]\n
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface Adress {\n latitude:\tnumber\n longitude:\tnumber\n countryCode:\tstring\n countryName:\tstring\n postalCode:\tstring\n administrativeArea:\tstring\n subAdministrativeArea:\tstring\n locality:\tstring\n subLocality:\tstring\n thoroughfare:\tstring\n subThoroughfare:\tstring\n areasOfInterest:\tstring[]\n}\n\nexport interface ForwardOptions {\n /**\n * address is a string of the address to be geocoded.\n */\n addressString:\tstring\n /**\n * Localise the results to the given locale.\n */\n useLocale?:\tboolean\n /**\n * locale is a string in the format of language_country, for example en_US.\n */\n defaultLocale?:\tstring\n /**\n * Max number of results to return.\n */\n maxResults?:\tnumber\n /**\n * Only used for web platform to use google api\n */\n apiKey?:\tstring\n}\nexport interface reverseOptions {\n /**\n * latitude is a number representing the latitude of the location.\n */\n latitude:\tnumber\n /**\n * longitude is a number representing the longitude of the location.\n */\n longitude:\tnumber\n /**\n * Localise the results to the given locale.\n */\n useLocale?:\tboolean\n /**\n * locale is a string in the format of language_country, for example en_US.\n */\n defaultLocale?:\tstring\n /**\n * Max number of results to return.\n */\n maxResults?:\tnumber\n /**\n * Only used for web platform to use google api\n */\n apiKey?:\tstring\n}\nexport interface NativeGeocoderPlugin {\n /**\n * Convert latitude and longitude to an address\n *\n * @param id The bundle id to delete (note, this is the bundle id, NOT the version name)\n * @returns {Promise<{addresses: Adress[]}>} an Promise with the list of addresses according to maxResults\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n reverseGeocode(options: reverseOptions): Promise<{ addresses:\tAdress[] }>;\n /**\n * Convert an address to latitude and longitude\n *\n * @returns {Promise<{addresses: Adress[]}>} an Promise with the list of addresses according to maxResults\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n forwardGeocode(options: ForwardOptions): Promise<{ addresses:\tAdress[] }>;\n}\n"]}
|
package/dist/esm/web.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
const findAC = (address_components, type) => {
|
|
3
|
+
return address_components.find(component => component.types.includes(type)) || { long_name: '', short_name: '', types: [] };
|
|
4
|
+
};
|
|
2
5
|
export class NativeGeocoderWeb extends WebPlugin {
|
|
3
6
|
async reverseGeocode(options) {
|
|
4
7
|
if (!options.apiKey) {
|
|
@@ -7,25 +10,27 @@ export class NativeGeocoderWeb extends WebPlugin {
|
|
|
7
10
|
const params = Object.assign(Object.assign({ latlng: `${options.latitude},${options.longitude}`, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: 'street_address' });
|
|
8
11
|
return fetch(`https://maps.googleapis.com/maps/api/geocode/json${new URLSearchParams(params).toString()}`)
|
|
9
12
|
.then(response => response.json())
|
|
10
|
-
.then(data => {
|
|
11
|
-
return
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
13
|
+
.then((data) => {
|
|
14
|
+
return {
|
|
15
|
+
addresses: data.results.forEach((result) => {
|
|
16
|
+
// transform the response in Adress[]
|
|
17
|
+
// use the restul from google geocoder and transform it in Adress
|
|
18
|
+
return {
|
|
19
|
+
latitude: result.geometry.location.lat,
|
|
20
|
+
longitude: result.geometry.location.lng,
|
|
21
|
+
countryCode: findAC(result.address_components, 'country').short_name,
|
|
22
|
+
countryName: findAC(result.address_components, 'country').long_name,
|
|
23
|
+
postalCode: findAC(result.address_components, 'postal_code').long_name,
|
|
24
|
+
administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,
|
|
25
|
+
subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,
|
|
26
|
+
locality: findAC(result.address_components, 'locality').long_name,
|
|
27
|
+
subLocality: findAC(result.address_components, 'sublocality').long_name,
|
|
28
|
+
thoroughfare: findAC(result.address_components, 'route').long_name,
|
|
29
|
+
subThoroughfare: findAC(result.address_components, 'street_number').long_name,
|
|
30
|
+
areasOfInterest: [],
|
|
31
|
+
};
|
|
32
|
+
}).slice(0, options.maxResults || 1)
|
|
33
|
+
};
|
|
29
34
|
});
|
|
30
35
|
}
|
|
31
36
|
;
|
|
@@ -36,25 +41,27 @@ export class NativeGeocoderWeb extends WebPlugin {
|
|
|
36
41
|
const params = Object.assign(Object.assign({ address: options.addressString, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: 'street_address' });
|
|
37
42
|
return fetch(`https://maps.googleapis.com/maps/api/geocode/json${new URLSearchParams(params).toString()}`)
|
|
38
43
|
.then(response => response.json())
|
|
39
|
-
.then(data => {
|
|
40
|
-
return
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
44
|
+
.then((data) => {
|
|
45
|
+
return {
|
|
46
|
+
addresses: data.results.forEach((result) => {
|
|
47
|
+
// transform the response in Adress[]
|
|
48
|
+
// use the restul from google geocoder and transform it in Adress
|
|
49
|
+
return {
|
|
50
|
+
latitude: result.geometry.location.lat,
|
|
51
|
+
longitude: result.geometry.location.lng,
|
|
52
|
+
countryCode: findAC(result.address_components, 'country').short_name,
|
|
53
|
+
countryName: findAC(result.address_components, 'country').long_name,
|
|
54
|
+
postalCode: findAC(result.address_components, 'postal_code').long_name,
|
|
55
|
+
administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,
|
|
56
|
+
subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,
|
|
57
|
+
locality: findAC(result.address_components, 'locality').long_name,
|
|
58
|
+
subLocality: findAC(result.address_components, 'sublocality').long_name,
|
|
59
|
+
thoroughfare: findAC(result.address_components, 'route').long_name,
|
|
60
|
+
subThoroughfare: findAC(result.address_components, 'street_number').long_name,
|
|
61
|
+
areasOfInterest: [],
|
|
62
|
+
};
|
|
63
|
+
}).slice(0, options.maxResults || 1)
|
|
64
|
+
};
|
|
58
65
|
});
|
|
59
66
|
}
|
|
60
67
|
;
|
package/dist/esm/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"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AM,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,CAAA;gBACH,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC;aACrC,CAAA;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;IAAA,CAAC;CACP","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { NativeGeocoderPlugin, reverseOptions, ForwardOptions, Adress } from './definitions';\n\ninterface AddressComponent {\n long_name: string;\n short_name: string;\n types: string[];\n}\n interface 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 }\n\nconst findAC = (address_components: AddressComponent[], type: string): AddressComponent => {\n return address_components.find(component => component.types.includes(type)) || { long_name: '', short_name: '', types: [] };\n}\nexport class NativeGeocoderWeb\n extends WebPlugin\n implements NativeGeocoderPlugin {\n async reverseGeocode(options: reverseOptions): Promise<{ addresses:\tAdress[] }> {\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(`https://maps.googleapis.com/maps/api/geocode/json${new URLSearchParams(params).toString()}`)\n .then(response => response.json())\n .then((data): { addresses:\tAdress[] } => {\n return { \n addresses: data.results.forEach((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').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 }).slice(0, options.maxResults || 1)\n }\n });\n };\n async forwardGeocode(options: ForwardOptions): Promise<{ addresses:\tAdress[] }> {\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): { addresses:\tAdress[] } => {\n return { \n addresses: data.results.forEach((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').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 }).slice(0, options.maxResults || 1)\n }\n })\n };\n}\n"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -8,6 +8,9 @@ const NativeGeocoder = core.registerPlugin('NativeGeocoder', {
|
|
|
8
8
|
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.NativeGeocoderWeb()),
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
+
const findAC = (address_components, type) => {
|
|
12
|
+
return address_components.find(component => component.types.includes(type)) || { long_name: '', short_name: '', types: [] };
|
|
13
|
+
};
|
|
11
14
|
class NativeGeocoderWeb extends core.WebPlugin {
|
|
12
15
|
async reverseGeocode(options) {
|
|
13
16
|
if (!options.apiKey) {
|
|
@@ -16,25 +19,27 @@ class NativeGeocoderWeb extends core.WebPlugin {
|
|
|
16
19
|
const params = Object.assign(Object.assign({ latlng: `${options.latitude},${options.longitude}`, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: 'street_address' });
|
|
17
20
|
return fetch(`https://maps.googleapis.com/maps/api/geocode/json${new URLSearchParams(params).toString()}`)
|
|
18
21
|
.then(response => response.json())
|
|
19
|
-
.then(data => {
|
|
20
|
-
return
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
22
|
+
.then((data) => {
|
|
23
|
+
return {
|
|
24
|
+
addresses: data.results.forEach((result) => {
|
|
25
|
+
// transform the response in Adress[]
|
|
26
|
+
// use the restul from google geocoder and transform it in Adress
|
|
27
|
+
return {
|
|
28
|
+
latitude: result.geometry.location.lat,
|
|
29
|
+
longitude: result.geometry.location.lng,
|
|
30
|
+
countryCode: findAC(result.address_components, 'country').short_name,
|
|
31
|
+
countryName: findAC(result.address_components, 'country').long_name,
|
|
32
|
+
postalCode: findAC(result.address_components, 'postal_code').long_name,
|
|
33
|
+
administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,
|
|
34
|
+
subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,
|
|
35
|
+
locality: findAC(result.address_components, 'locality').long_name,
|
|
36
|
+
subLocality: findAC(result.address_components, 'sublocality').long_name,
|
|
37
|
+
thoroughfare: findAC(result.address_components, 'route').long_name,
|
|
38
|
+
subThoroughfare: findAC(result.address_components, 'street_number').long_name,
|
|
39
|
+
areasOfInterest: [],
|
|
40
|
+
};
|
|
41
|
+
}).slice(0, options.maxResults || 1)
|
|
42
|
+
};
|
|
38
43
|
});
|
|
39
44
|
}
|
|
40
45
|
;
|
|
@@ -45,25 +50,27 @@ class NativeGeocoderWeb extends core.WebPlugin {
|
|
|
45
50
|
const params = Object.assign(Object.assign({ address: options.addressString, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: 'street_address' });
|
|
46
51
|
return fetch(`https://maps.googleapis.com/maps/api/geocode/json${new URLSearchParams(params).toString()}`)
|
|
47
52
|
.then(response => response.json())
|
|
48
|
-
.then(data => {
|
|
49
|
-
return
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
53
|
+
.then((data) => {
|
|
54
|
+
return {
|
|
55
|
+
addresses: data.results.forEach((result) => {
|
|
56
|
+
// transform the response in Adress[]
|
|
57
|
+
// use the restul from google geocoder and transform it in Adress
|
|
58
|
+
return {
|
|
59
|
+
latitude: result.geometry.location.lat,
|
|
60
|
+
longitude: result.geometry.location.lng,
|
|
61
|
+
countryCode: findAC(result.address_components, 'country').short_name,
|
|
62
|
+
countryName: findAC(result.address_components, 'country').long_name,
|
|
63
|
+
postalCode: findAC(result.address_components, 'postal_code').long_name,
|
|
64
|
+
administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,
|
|
65
|
+
subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,
|
|
66
|
+
locality: findAC(result.address_components, 'locality').long_name,
|
|
67
|
+
subLocality: findAC(result.address_components, 'sublocality').long_name,
|
|
68
|
+
thoroughfare: findAC(result.address_components, 'route').long_name,
|
|
69
|
+
subThoroughfare: findAC(result.address_components, 'street_number').long_name,
|
|
70
|
+
areasOfInterest: [],
|
|
71
|
+
};
|
|
72
|
+
}).slice(0, options.maxResults || 1)
|
|
73
|
+
};
|
|
67
74
|
});
|
|
68
75
|
}
|
|
69
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 '@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';\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 data.results.forEach((result) => {\n
|
|
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)) || { long_name: '', short_name: '', types: [] };\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.forEach((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').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 }).slice(0, options.maxResults || 1)\n };\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.forEach((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').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 }).slice(0, options.maxResults || 1)\n };\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,IAAI,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;AACnE,CAAC;;ACFD,MAAM,MAAM,GAAG,CAAC,kBAAkB,EAAE,IAAI,KAAK;AAC7C,IAAI,OAAO,kBAAkB,CAAC,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;AAChI,CAAC,CAAC;AACK,MAAM,iBAAiB,SAASC,cAAS,CAAC;AACjD,IAAI,MAAM,cAAc,CAAC,OAAO,EAAE;AAClC,QAAQ,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;AAC7B,YAAY,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;AAC1D,SAAS;AACT,QAAQ,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,aAAa,EAA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G;AAC9D,wBAAwB,SAAS,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG;AAC/D,wBAAwB,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC,UAAU;AAC5F,wBAAwB,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC,SAAS;AAC3F,wBAAwB,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,aAAa,CAAC,CAAC,SAAS;AAC9F,wBAAwB,kBAAkB,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,6BAA6B,CAAC,CAAC,SAAS;AACtH,wBAAwB,qBAAqB,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,6BAA6B,CAAC,CAAC,SAAS;AACzH,wBAAwB,QAAQ,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,CAAC;AACtB,iBAAiB,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC;AACpD,aAAa,CAAC;AACd,SAAS,CAAC,CAAC;AACX,KAAK;AACL;AACA;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -5,6 +5,9 @@ var capacitorNativeGeocoder = (function (exports, core) {
|
|
|
5
5
|
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.NativeGeocoderWeb()),
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
+
const findAC = (address_components, type) => {
|
|
9
|
+
return address_components.find(component => component.types.includes(type)) || { long_name: '', short_name: '', types: [] };
|
|
10
|
+
};
|
|
8
11
|
class NativeGeocoderWeb extends core.WebPlugin {
|
|
9
12
|
async reverseGeocode(options) {
|
|
10
13
|
if (!options.apiKey) {
|
|
@@ -13,25 +16,27 @@ var capacitorNativeGeocoder = (function (exports, core) {
|
|
|
13
16
|
const params = Object.assign(Object.assign({ latlng: `${options.latitude},${options.longitude}`, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: 'street_address' });
|
|
14
17
|
return fetch(`https://maps.googleapis.com/maps/api/geocode/json${new URLSearchParams(params).toString()}`)
|
|
15
18
|
.then(response => response.json())
|
|
16
|
-
.then(data => {
|
|
17
|
-
return
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
19
|
+
.then((data) => {
|
|
20
|
+
return {
|
|
21
|
+
addresses: data.results.forEach((result) => {
|
|
22
|
+
// transform the response in Adress[]
|
|
23
|
+
// use the restul from google geocoder and transform it in Adress
|
|
24
|
+
return {
|
|
25
|
+
latitude: result.geometry.location.lat,
|
|
26
|
+
longitude: result.geometry.location.lng,
|
|
27
|
+
countryCode: findAC(result.address_components, 'country').short_name,
|
|
28
|
+
countryName: findAC(result.address_components, 'country').long_name,
|
|
29
|
+
postalCode: findAC(result.address_components, 'postal_code').long_name,
|
|
30
|
+
administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,
|
|
31
|
+
subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,
|
|
32
|
+
locality: findAC(result.address_components, 'locality').long_name,
|
|
33
|
+
subLocality: findAC(result.address_components, 'sublocality').long_name,
|
|
34
|
+
thoroughfare: findAC(result.address_components, 'route').long_name,
|
|
35
|
+
subThoroughfare: findAC(result.address_components, 'street_number').long_name,
|
|
36
|
+
areasOfInterest: [],
|
|
37
|
+
};
|
|
38
|
+
}).slice(0, options.maxResults || 1)
|
|
39
|
+
};
|
|
35
40
|
});
|
|
36
41
|
}
|
|
37
42
|
;
|
|
@@ -42,25 +47,27 @@ var capacitorNativeGeocoder = (function (exports, core) {
|
|
|
42
47
|
const params = Object.assign(Object.assign({ address: options.addressString, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: 'street_address' });
|
|
43
48
|
return fetch(`https://maps.googleapis.com/maps/api/geocode/json${new URLSearchParams(params).toString()}`)
|
|
44
49
|
.then(response => response.json())
|
|
45
|
-
.then(data => {
|
|
46
|
-
return
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
50
|
+
.then((data) => {
|
|
51
|
+
return {
|
|
52
|
+
addresses: data.results.forEach((result) => {
|
|
53
|
+
// transform the response in Adress[]
|
|
54
|
+
// use the restul from google geocoder and transform it in Adress
|
|
55
|
+
return {
|
|
56
|
+
latitude: result.geometry.location.lat,
|
|
57
|
+
longitude: result.geometry.location.lng,
|
|
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,
|
|
67
|
+
areasOfInterest: [],
|
|
68
|
+
};
|
|
69
|
+
}).slice(0, options.maxResults || 1)
|
|
70
|
+
};
|
|
64
71
|
});
|
|
65
72
|
}
|
|
66
73
|
;
|
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 '@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';\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 data.results.forEach((result) => {\n
|
|
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)) || { long_name: '', short_name: '', types: [] };\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.forEach((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').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 }).slice(0, options.maxResults || 1)\n };\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.forEach((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').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 }).slice(0, options.maxResults || 1)\n };\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,IAAI,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;IACnE,CAAC;;ICFD,MAAM,MAAM,GAAG,CAAC,kBAAkB,EAAE,IAAI,KAAK;IAC7C,IAAI,OAAO,kBAAkB,CAAC,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;IAChI,CAAC,CAAC;IACK,MAAM,iBAAiB,SAASC,cAAS,CAAC;IACjD,IAAI,MAAM,cAAc,CAAC,OAAO,EAAE;IAClC,QAAQ,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;IAC7B,YAAY,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAC1D,SAAS;IACT,QAAQ,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,aAAa,EAAE,EAAE,EAAE,EAAE,WAAW,EAAE,gBAAgB,EAAE,CAAC,CAAC;IACpO,QAAQ,OAAO,KAAK,CAAC,CA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