@capgo/nativegeocoder 0.1.14 → 0.1.17

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Capgo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
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
@@ -130,3 +130,6 @@ Convert an address to latitude and longitude
130
130
  | **`apiKey`** | <code>string</code> | Only used for web platform to use google api |
131
131
 
132
132
  </docgen-api>
133
+
134
+ ## Thanks
135
+ To [@sebastianbaar](https://github.com/sebastianbaar) and his work on [cordova-plugin-nativegeocoder](https://github.com/sebastianbaar/cordova-plugin-nativegeocoder) what he made was very inspiring
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 formatted_address: string\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"]}
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 data.results.forEach((result) => {
12
- // transform the response in Adress[]
13
- // use the restul from google geocoder and transform it in Adress
14
- return {
15
- latitude: result.geometry.location.lat,
16
- longitude: result.geometry.location.lng,
17
- countryCode: result.address_components[0].long_name,
18
- postalCode: result.address_components[1].long_name,
19
- administrativeArea: result.address_components[2].long_name,
20
- subAdministrativeArea: result.address_components[3].long_name,
21
- locality: result.address_components[4].long_name,
22
- subLocality: result.address_components[5].long_name,
23
- thoroughfare: result.address_components[6].long_name,
24
- subThoroughfare: result.address_components[7].long_name,
25
- areasOfInterest: result.address_components[8].long_name,
26
- formatted_address: result.formatted_address,
27
- };
28
- }).slice(0, options.maxResults || 1);
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 data.results.forEach((result) => {
41
- // transform the response in Adress[]
42
- // use the restul from google geocoder and transform it in Adress
43
- return {
44
- latitude: result.geometry.location.lat,
45
- longitude: result.geometry.location.lng,
46
- countryCode: result.address_components[0].long_name,
47
- postalCode: result.address_components[1].long_name,
48
- administrativeArea: result.address_components[2].long_name,
49
- subAdministrativeArea: result.address_components[3].long_name,
50
- locality: result.address_components[4].long_name,
51
- subLocality: result.address_components[5].long_name,
52
- thoroughfare: result.address_components[6].long_name,
53
- subThoroughfare: result.address_components[7].long_name,
54
- areasOfInterest: result.address_components[8].long_name,
55
- formatted_address: result.formatted_address,
56
- };
57
- }).slice(0, options.maxResults || 1);
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
  ;
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AA8B5C,MAAM,OAAO,i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AC,QAAQ,CAAC,GAAG;oBACvC,WAAW,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS;oBACnD,UAAU,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS;oBAClD,kBAAkB,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS;oBAC1D,qBAAqB,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS;oBAC7D,QAAQ,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS;oBAChD,WAAW,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS;oBACnD,YAAY,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS;oBACpD,eAAe,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS;oBACvD,eAAe,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS;oBACvD,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;iBAC5C,CAAA;YACH,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC,CAAA;QACtC,CAAC,CAAC,CAAC;IACL,CAAC;IAAA,CAAC;CACP","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { NativeGeocoderPlugin, reverseOptions, ForwardOptions, Adress } from './definitions';\n\ninterface GeocoderResult {\n address_components: {\n long_name: string;\n short_name: string;\n types: string[];\n }[];\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\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 => {\n return data.results.forEach((result: GeocoderResult) => {\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: result.address_components[0].long_name,\n postalCode: result.address_components[1].long_name,\n administrativeArea: result.address_components[2].long_name,\n subAdministrativeArea: result.address_components[3].long_name,\n locality: result.address_components[4].long_name,\n subLocality: result.address_components[5].long_name,\n thoroughfare: result.address_components[6].long_name,\n subThoroughfare: result.address_components[7].long_name,\n areasOfInterest: result.address_components[8].long_name,\n formatted_address: result.formatted_address,\n }\n }).slice(0, options.maxResults || 1)\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 => {\n return data.results.forEach((result: GeocoderResult) => {\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: result.address_components[0].long_name,\n postalCode: result.address_components[1].long_name,\n administrativeArea: result.address_components[2].long_name,\n subAdministrativeArea: result.address_components[3].long_name,\n locality: result.address_components[4].long_name,\n subLocality: result.address_components[5].long_name,\n thoroughfare: result.address_components[6].long_name,\n subThoroughfare: result.address_components[7].long_name,\n areasOfInterest: result.address_components[8].long_name,\n formatted_address: result.formatted_address,\n }\n }).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AAY,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"]}
@@ -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 data.results.forEach((result) => {
21
- // transform the response in Adress[]
22
- // use the restul from google geocoder and transform it in Adress
23
- return {
24
- latitude: result.geometry.location.lat,
25
- longitude: result.geometry.location.lng,
26
- countryCode: result.address_components[0].long_name,
27
- postalCode: result.address_components[1].long_name,
28
- administrativeArea: result.address_components[2].long_name,
29
- subAdministrativeArea: result.address_components[3].long_name,
30
- locality: result.address_components[4].long_name,
31
- subLocality: result.address_components[5].long_name,
32
- thoroughfare: result.address_components[6].long_name,
33
- subThoroughfare: result.address_components[7].long_name,
34
- areasOfInterest: result.address_components[8].long_name,
35
- formatted_address: result.formatted_address,
36
- };
37
- }).slice(0, options.maxResults || 1);
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 data.results.forEach((result) => {
50
- // transform the response in Adress[]
51
- // use the restul from google geocoder and transform it in Adress
52
- return {
53
- latitude: result.geometry.location.lat,
54
- longitude: result.geometry.location.lng,
55
- countryCode: result.address_components[0].long_name,
56
- postalCode: result.address_components[1].long_name,
57
- administrativeArea: result.address_components[2].long_name,
58
- subAdministrativeArea: result.address_components[3].long_name,
59
- locality: result.address_components[4].long_name,
60
- subLocality: result.address_components[5].long_name,
61
- thoroughfare: result.address_components[6].long_name,
62
- subThoroughfare: result.address_components[7].long_name,
63
- areasOfInterest: result.address_components[8].long_name,
64
- formatted_address: result.formatted_address,
65
- };
66
- }).slice(0, options.maxResults || 1);
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
  ;
@@ -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 // 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: result.address_components[0].long_name,\n postalCode: result.address_components[1].long_name,\n administrativeArea: result.address_components[2].long_name,\n subAdministrativeArea: result.address_components[3].long_name,\n locality: result.address_components[4].long_name,\n subLocality: result.address_components[5].long_name,\n thoroughfare: result.address_components[6].long_name,\n subThoroughfare: result.address_components[7].long_name,\n areasOfInterest: result.address_components[8].long_name,\n formatted_address: result.formatted_address,\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 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: result.address_components[0].long_name,\n postalCode: result.address_components[1].long_name,\n administrativeArea: result.address_components[2].long_name,\n subAdministrativeArea: result.address_components[3].long_name,\n locality: result.address_components[4].long_name,\n subLocality: result.address_components[5].long_name,\n thoroughfare: result.address_components[6].long_name,\n subThoroughfare: result.address_components[7].long_name,\n areasOfInterest: result.address_components[8].long_name,\n formatted_address: result.formatted_address,\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,IAAI,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;AACnE,CAAC;;ACFM,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,EAAE,EAAE,EAAE,EAAE,WAAW,EAAE,gBAAgB,EAAE,CAAC,CAAC;AACp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kBAAkB,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS;AAC9E,oBAAoB,qBAAqB,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS;AACjF,oBAAoB,QAAQ,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS;AACpE,oBAAoB,WAAW,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS;AACvE,oBAAoB,YAAY,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS;AACxE,oBAAoB,eAAe,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS;AAC3E,oBAAoB,eAAe,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS;AAC3E,oBAAoB,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;AAC/D,iBAAiB,CAAC;AAClB,aAAa,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC,CAAC;AACjD,SAAS,CAAC,CAAC;AACX,KAAK;AACL;AACA;;;;;;;;;"}
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,\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AwB,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 data.results.forEach((result) => {
18
- // transform the response in Adress[]
19
- // use the restul from google geocoder and transform it in Adress
20
- return {
21
- latitude: result.geometry.location.lat,
22
- longitude: result.geometry.location.lng,
23
- countryCode: result.address_components[0].long_name,
24
- postalCode: result.address_components[1].long_name,
25
- administrativeArea: result.address_components[2].long_name,
26
- subAdministrativeArea: result.address_components[3].long_name,
27
- locality: result.address_components[4].long_name,
28
- subLocality: result.address_components[5].long_name,
29
- thoroughfare: result.address_components[6].long_name,
30
- subThoroughfare: result.address_components[7].long_name,
31
- areasOfInterest: result.address_components[8].long_name,
32
- formatted_address: result.formatted_address,
33
- };
34
- }).slice(0, options.maxResults || 1);
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 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: result.address_components[0].long_name,
53
- postalCode: result.address_components[1].long_name,
54
- administrativeArea: result.address_components[2].long_name,
55
- subAdministrativeArea: result.address_components[3].long_name,
56
- locality: result.address_components[4].long_name,
57
- subLocality: result.address_components[5].long_name,
58
- thoroughfare: result.address_components[6].long_name,
59
- subThoroughfare: result.address_components[7].long_name,
60
- areasOfInterest: result.address_components[8].long_name,
61
- formatted_address: result.formatted_address,
62
- };
63
- }).slice(0, options.maxResults || 1);
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
  ;
@@ -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 // 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: result.address_components[0].long_name,\n postalCode: result.address_components[1].long_name,\n administrativeArea: result.address_components[2].long_name,\n subAdministrativeArea: result.address_components[3].long_name,\n locality: result.address_components[4].long_name,\n subLocality: result.address_components[5].long_name,\n thoroughfare: result.address_components[6].long_name,\n subThoroughfare: result.address_components[7].long_name,\n areasOfInterest: result.address_components[8].long_name,\n formatted_address: result.formatted_address,\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 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: result.address_components[0].long_name,\n postalCode: result.address_components[1].long_name,\n administrativeArea: result.address_components[2].long_name,\n subAdministrativeArea: result.address_components[3].long_name,\n locality: result.address_components[4].long_name,\n subLocality: result.address_components[5].long_name,\n thoroughfare: result.address_components[6].long_name,\n subThoroughfare: result.address_components[7].long_name,\n areasOfInterest: result.address_components[8].long_name,\n formatted_address: result.formatted_address,\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,IAAI,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;IACnE,CAAC;;ICFM,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,CAAC,iDAAiD,EAAE,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;IAClH,aAAa,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,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,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS;IACpE,oBAAoB,WAAW,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS;IACvE,oBAAoB,YAAY,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS;IACxE,oBAAoB,eAAe,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS;IAC3E,oBAAoB,eAAe,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS;IAC3E,oBAAoB,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;IAC/D,iBAAiB,CAAC;IAClB,aAAa,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC,CAAC;IACjD,SAAS,CAAC,CAAC;IACX,KAAK;IACL;IACA;;;;;;;;;;;;;;;;;"}
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,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AAS;IAC9F,wBAAwB,kBAAkB,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,6BAA6B,CAAC,CAAC,SAAS;IACtH,wBAAwB,qBAAqB,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,6BAA6B,CAAC,CAAC,SAAS;IACzH,wBAAwB,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,UAAU,CAAC,CAAC,SAAS;IACzF,wBAAwB,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,aAAa,CAAC,CAAC,SAAS;IAC/F,wBAAwB,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC,SAAS;IAC1F,wBAAwB,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC,SAAS;IACrG,wBAAwB,eAAe,EAAE,EAAE;IAC3C,qBAAqB,CAAC;IACtB,iBAAiB,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC;IACpD,aAAa,CAAC;IACd,SAAS,CAAC,CAAC;IACX,KAAK;IACL;IACA;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/nativegeocoder",
3
- "version": "0.1.14",
3
+ "version": "0.1.17",
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",