@capgo/capacitor-nativegeocoder 8.0.32
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/CapgoCapacitorNativegeocoder.podspec +17 -0
- package/LICENSE +373 -0
- package/Package.swift +28 -0
- package/README.md +180 -0
- package/android/build.gradle +59 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/ee/forgr/capacitor_nativegeocoder/NativeGeocoder.java +229 -0
- package/android/src/main/java/ee/forgr/capacitor_nativegeocoder/NativeGeocoderPlugin.java +53 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +298 -0
- package/dist/esm/definitions.d.ts +98 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +13 -0
- package/dist/esm/web.js +78 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +92 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +95 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/NativeGeocoderPlugin/NativeGeocoder.swift +194 -0
- package/ios/Sources/NativeGeocoderPlugin/NativeGeocoderPlugin.swift +44 -0
- package/ios/Tests/NativeGeocoderPluginTests/NativeGeocoderTests.swift +16 -0
- package/package.json +88 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { registerPlugin } from '@capacitor/core';
|
|
2
|
+
const NativeGeocoder = registerPlugin('NativeGeocoder', {
|
|
3
|
+
web: () => import('./web').then((m) => new m.NativeGeocoderWeb()),
|
|
4
|
+
});
|
|
5
|
+
export * from './definitions';
|
|
6
|
+
export { NativeGeocoder };
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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 '@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"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { NativeGeocoderPlugin, ReverseOptions, ForwardOptions, Address } from './definitions';
|
|
3
|
+
export declare class NativeGeocoderWeb extends WebPlugin implements NativeGeocoderPlugin {
|
|
4
|
+
reverseGeocode(options: ReverseOptions): Promise<{
|
|
5
|
+
addresses: Address[];
|
|
6
|
+
}>;
|
|
7
|
+
forwardGeocode(options: ForwardOptions): Promise<{
|
|
8
|
+
addresses: Address[];
|
|
9
|
+
}>;
|
|
10
|
+
getPluginVersion(): Promise<{
|
|
11
|
+
version: string;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
const findAC = (address_components, type) => {
|
|
3
|
+
return (address_components.find((component) => component.types.includes(type)) || {
|
|
4
|
+
long_name: '',
|
|
5
|
+
short_name: '',
|
|
6
|
+
types: [],
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
export class NativeGeocoderWeb extends WebPlugin {
|
|
10
|
+
async reverseGeocode(options) {
|
|
11
|
+
if (!options.apiKey) {
|
|
12
|
+
throw new Error('apiKey is required for web');
|
|
13
|
+
}
|
|
14
|
+
const params = Object.assign(Object.assign({ latlng: `${options.latitude},${options.longitude}`, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: options.resultType || 'street_address' });
|
|
15
|
+
return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)
|
|
16
|
+
.then((response) => response.json())
|
|
17
|
+
.then((data) => {
|
|
18
|
+
return {
|
|
19
|
+
addresses: data.results
|
|
20
|
+
.map((result) => {
|
|
21
|
+
// transform the response in Address[]
|
|
22
|
+
// use the result from google geocoder and transform it in Address
|
|
23
|
+
return {
|
|
24
|
+
latitude: result.geometry.location.lat,
|
|
25
|
+
longitude: result.geometry.location.lng,
|
|
26
|
+
countryCode: findAC(result.address_components, 'country').short_name,
|
|
27
|
+
countryName: findAC(result.address_components, 'country').long_name,
|
|
28
|
+
postalCode: findAC(result.address_components, 'postal_code').long_name,
|
|
29
|
+
administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,
|
|
30
|
+
subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,
|
|
31
|
+
locality: findAC(result.address_components, 'locality').long_name,
|
|
32
|
+
subLocality: findAC(result.address_components, 'sublocality').long_name,
|
|
33
|
+
thoroughfare: findAC(result.address_components, 'route').long_name,
|
|
34
|
+
subThoroughfare: findAC(result.address_components, 'street_number').long_name,
|
|
35
|
+
areasOfInterest: [],
|
|
36
|
+
};
|
|
37
|
+
})
|
|
38
|
+
.slice(0, options.maxResults || 1),
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async forwardGeocode(options) {
|
|
43
|
+
if (!options.apiKey) {
|
|
44
|
+
throw new Error('apiKey is required for web');
|
|
45
|
+
}
|
|
46
|
+
const params = Object.assign(Object.assign({ address: options.addressString, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: 'street_address' });
|
|
47
|
+
return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)
|
|
48
|
+
.then((response) => response.json())
|
|
49
|
+
.then((data) => {
|
|
50
|
+
return {
|
|
51
|
+
addresses: data.results
|
|
52
|
+
.map((result) => {
|
|
53
|
+
// transform the response in Address[]
|
|
54
|
+
// use the result from google geocoder and transform it in Address
|
|
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
|
+
})
|
|
70
|
+
.slice(0, options.maxResults || 1),
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async getPluginVersion() {
|
|
75
|
+
return { version: 'web' };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAsC5C,MAAM,MAAM,GAAG,CAAC,kBAAsC,EAAE,IAAY,EAAoB,EAAE;IACxF,OAAO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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;IAED,KAAK,CAAC,gBAAgB;QACpB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { NativeGeocoderPlugin, ReverseOptions, ForwardOptions, Address } from './definitions';\n\ninterface AddressComponent {\n long_name: string;\n short_name: string;\n types: string[];\n}\ninterface GeocoderResult {\n address_components: AddressComponent[];\n formatted_address: string;\n geometry: {\n location: {\n lat: number;\n lng: number;\n };\n location_type: string;\n viewport: {\n northeast: {\n lat: number;\n lng: number;\n };\n southwest: {\n lat: number;\n lng: number;\n };\n };\n };\n}\ninterface GeocoderPayload {\n plus_code: {\n compound_code: string;\n global_code: string;\n };\n results: GeocoderResult[];\n}\n\nconst findAC = (address_components: AddressComponent[], type: string): AddressComponent => {\n return (\n address_components.find((component) => component.types.includes(type)) || {\n long_name: '',\n short_name: '',\n types: [],\n }\n );\n};\nexport class NativeGeocoderWeb extends WebPlugin implements NativeGeocoderPlugin {\n async reverseGeocode(options: ReverseOptions): Promise<{ addresses: Address[] }> {\n if (!options.apiKey) {\n throw new Error('apiKey is required for web');\n }\n const params = {\n latlng: `${options.latitude},${options.longitude}`,\n key: options.apiKey,\n ...(options.defaultLocale && { language: options.defaultLocale }),\n result_type: options.resultType || 'street_address',\n };\n return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)\n .then((response) => response.json())\n .then((data: GeocoderPayload): { addresses: Address[] } => {\n return {\n addresses: data.results\n .map((result: GeocoderResult): Address => {\n // transform the response in Address[]\n // use the result from google geocoder and transform it in Address\n\n return {\n latitude: result.geometry.location.lat,\n longitude: result.geometry.location.lng,\n countryCode: findAC(result.address_components, 'country').short_name,\n countryName: findAC(result.address_components, 'country').long_name,\n postalCode: findAC(result.address_components, 'postal_code').long_name,\n administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,\n subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,\n locality: findAC(result.address_components, 'locality').long_name,\n subLocality: findAC(result.address_components, 'sublocality').long_name,\n thoroughfare: findAC(result.address_components, 'route').long_name,\n subThoroughfare: findAC(result.address_components, 'street_number').long_name,\n areasOfInterest: [],\n };\n })\n .slice(0, options.maxResults || 1),\n };\n });\n }\n async forwardGeocode(options: ForwardOptions): Promise<{ addresses: Address[] }> {\n if (!options.apiKey) {\n throw new Error('apiKey is required for web');\n }\n const params = {\n address: options.addressString,\n key: options.apiKey,\n ...(options.defaultLocale && { language: options.defaultLocale }),\n result_type: 'street_address',\n };\n return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)\n .then((response) => response.json())\n .then((data: GeocoderPayload): { addresses: Address[] } => {\n return {\n addresses: data.results\n .map((result: GeocoderResult): Address => {\n // transform the response in Address[]\n // use the result from google geocoder and transform it in Address\n return {\n latitude: result.geometry.location.lat,\n longitude: result.geometry.location.lng,\n countryCode: findAC(result.address_components, 'country').short_name,\n countryName: findAC(result.address_components, 'country').long_name,\n postalCode: findAC(result.address_components, 'postal_code').long_name,\n administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,\n subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,\n locality: findAC(result.address_components, 'locality').long_name,\n subLocality: findAC(result.address_components, 'sublocality').long_name,\n thoroughfare: findAC(result.address_components, 'route').long_name,\n subThoroughfare: findAC(result.address_components, 'street_number').long_name,\n areasOfInterest: [],\n };\n })\n .slice(0, options.maxResults || 1),\n };\n });\n }\n\n async getPluginVersion(): Promise<{ version: string }> {\n return { version: 'web' };\n }\n}\n"]}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@capacitor/core');
|
|
4
|
+
|
|
5
|
+
const NativeGeocoder = core.registerPlugin('NativeGeocoder', {
|
|
6
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.NativeGeocoderWeb()),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const findAC = (address_components, type) => {
|
|
10
|
+
return (address_components.find((component) => component.types.includes(type)) || {
|
|
11
|
+
long_name: '',
|
|
12
|
+
short_name: '',
|
|
13
|
+
types: [],
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
class NativeGeocoderWeb extends core.WebPlugin {
|
|
17
|
+
async reverseGeocode(options) {
|
|
18
|
+
if (!options.apiKey) {
|
|
19
|
+
throw new Error('apiKey is required for web');
|
|
20
|
+
}
|
|
21
|
+
const params = Object.assign(Object.assign({ latlng: `${options.latitude},${options.longitude}`, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: options.resultType || 'street_address' });
|
|
22
|
+
return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)
|
|
23
|
+
.then((response) => response.json())
|
|
24
|
+
.then((data) => {
|
|
25
|
+
return {
|
|
26
|
+
addresses: data.results
|
|
27
|
+
.map((result) => {
|
|
28
|
+
// transform the response in Address[]
|
|
29
|
+
// use the result from google geocoder and transform it in Address
|
|
30
|
+
return {
|
|
31
|
+
latitude: result.geometry.location.lat,
|
|
32
|
+
longitude: result.geometry.location.lng,
|
|
33
|
+
countryCode: findAC(result.address_components, 'country').short_name,
|
|
34
|
+
countryName: findAC(result.address_components, 'country').long_name,
|
|
35
|
+
postalCode: findAC(result.address_components, 'postal_code').long_name,
|
|
36
|
+
administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,
|
|
37
|
+
subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,
|
|
38
|
+
locality: findAC(result.address_components, 'locality').long_name,
|
|
39
|
+
subLocality: findAC(result.address_components, 'sublocality').long_name,
|
|
40
|
+
thoroughfare: findAC(result.address_components, 'route').long_name,
|
|
41
|
+
subThoroughfare: findAC(result.address_components, 'street_number').long_name,
|
|
42
|
+
areasOfInterest: [],
|
|
43
|
+
};
|
|
44
|
+
})
|
|
45
|
+
.slice(0, options.maxResults || 1),
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
async forwardGeocode(options) {
|
|
50
|
+
if (!options.apiKey) {
|
|
51
|
+
throw new Error('apiKey is required for web');
|
|
52
|
+
}
|
|
53
|
+
const params = Object.assign(Object.assign({ address: options.addressString, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: 'street_address' });
|
|
54
|
+
return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)
|
|
55
|
+
.then((response) => response.json())
|
|
56
|
+
.then((data) => {
|
|
57
|
+
return {
|
|
58
|
+
addresses: data.results
|
|
59
|
+
.map((result) => {
|
|
60
|
+
// transform the response in Address[]
|
|
61
|
+
// use the result from google geocoder and transform it in Address
|
|
62
|
+
return {
|
|
63
|
+
latitude: result.geometry.location.lat,
|
|
64
|
+
longitude: result.geometry.location.lng,
|
|
65
|
+
countryCode: findAC(result.address_components, 'country').short_name,
|
|
66
|
+
countryName: findAC(result.address_components, 'country').long_name,
|
|
67
|
+
postalCode: findAC(result.address_components, 'postal_code').long_name,
|
|
68
|
+
administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,
|
|
69
|
+
subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,
|
|
70
|
+
locality: findAC(result.address_components, 'locality').long_name,
|
|
71
|
+
subLocality: findAC(result.address_components, 'sublocality').long_name,
|
|
72
|
+
thoroughfare: findAC(result.address_components, 'route').long_name,
|
|
73
|
+
subThoroughfare: findAC(result.address_components, 'street_number').long_name,
|
|
74
|
+
areasOfInterest: [],
|
|
75
|
+
};
|
|
76
|
+
})
|
|
77
|
+
.slice(0, options.maxResults || 1),
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
async getPluginVersion() {
|
|
82
|
+
return { version: 'web' };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
87
|
+
__proto__: null,
|
|
88
|
+
NativeGeocoderWeb: NativeGeocoderWeb
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
exports.NativeGeocoder = NativeGeocoder;
|
|
92
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +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';\nconst findAC = (address_components, type) => {\n return (address_components.find((component) => component.types.includes(type)) || {\n long_name: '',\n short_name: '',\n types: [],\n });\n};\nexport class NativeGeocoderWeb extends WebPlugin {\n async reverseGeocode(options) {\n if (!options.apiKey) {\n throw new Error('apiKey is required for web');\n }\n const params = Object.assign(Object.assign({ latlng: `${options.latitude},${options.longitude}`, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: options.resultType || 'street_address' });\n return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)\n .then((response) => response.json())\n .then((data) => {\n return {\n addresses: data.results\n .map((result) => {\n // transform the response in Address[]\n // use the result from google geocoder and transform it in Address\n return {\n latitude: result.geometry.location.lat,\n longitude: result.geometry.location.lng,\n countryCode: findAC(result.address_components, 'country').short_name,\n countryName: findAC(result.address_components, 'country').long_name,\n postalCode: findAC(result.address_components, 'postal_code').long_name,\n administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,\n subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,\n locality: findAC(result.address_components, 'locality').long_name,\n subLocality: findAC(result.address_components, 'sublocality').long_name,\n thoroughfare: findAC(result.address_components, 'route').long_name,\n subThoroughfare: findAC(result.address_components, 'street_number').long_name,\n areasOfInterest: [],\n };\n })\n .slice(0, options.maxResults || 1),\n };\n });\n }\n async forwardGeocode(options) {\n if (!options.apiKey) {\n throw new Error('apiKey is required for web');\n }\n const params = Object.assign(Object.assign({ address: options.addressString, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: 'street_address' });\n return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)\n .then((response) => response.json())\n .then((data) => {\n return {\n addresses: data.results\n .map((result) => {\n // transform the response in Address[]\n // use the result from google geocoder and transform it in Address\n return {\n latitude: result.geometry.location.lat,\n longitude: result.geometry.location.lng,\n countryCode: findAC(result.address_components, 'country').short_name,\n countryName: findAC(result.address_components, 'country').long_name,\n postalCode: findAC(result.address_components, 'postal_code').long_name,\n administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,\n subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,\n locality: findAC(result.address_components, 'locality').long_name,\n subLocality: findAC(result.address_components, 'sublocality').long_name,\n thoroughfare: findAC(result.address_components, 'route').long_name,\n subThoroughfare: findAC(result.address_components, 'street_number').long_name,\n areasOfInterest: [],\n };\n })\n .slice(0, options.maxResults || 1),\n };\n });\n }\n async getPluginVersion() {\n return { version: 'web' };\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,I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AAC,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;AACrB,gBAAgB,CAAC;AACjB,qBAAqB,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC;AACtD,aAAa;AACb,QAAQ,CAAC,CAAC;AACV,IAAI;AACJ,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;AACjC,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
var capacitorNativeGeocoder = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const NativeGeocoder = core.registerPlugin('NativeGeocoder', {
|
|
5
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.NativeGeocoderWeb()),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
const findAC = (address_components, type) => {
|
|
9
|
+
return (address_components.find((component) => component.types.includes(type)) || {
|
|
10
|
+
long_name: '',
|
|
11
|
+
short_name: '',
|
|
12
|
+
types: [],
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
class NativeGeocoderWeb extends core.WebPlugin {
|
|
16
|
+
async reverseGeocode(options) {
|
|
17
|
+
if (!options.apiKey) {
|
|
18
|
+
throw new Error('apiKey is required for web');
|
|
19
|
+
}
|
|
20
|
+
const params = Object.assign(Object.assign({ latlng: `${options.latitude},${options.longitude}`, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: options.resultType || 'street_address' });
|
|
21
|
+
return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)
|
|
22
|
+
.then((response) => response.json())
|
|
23
|
+
.then((data) => {
|
|
24
|
+
return {
|
|
25
|
+
addresses: data.results
|
|
26
|
+
.map((result) => {
|
|
27
|
+
// transform the response in Address[]
|
|
28
|
+
// use the result from google geocoder and transform it in Address
|
|
29
|
+
return {
|
|
30
|
+
latitude: result.geometry.location.lat,
|
|
31
|
+
longitude: result.geometry.location.lng,
|
|
32
|
+
countryCode: findAC(result.address_components, 'country').short_name,
|
|
33
|
+
countryName: findAC(result.address_components, 'country').long_name,
|
|
34
|
+
postalCode: findAC(result.address_components, 'postal_code').long_name,
|
|
35
|
+
administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,
|
|
36
|
+
subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,
|
|
37
|
+
locality: findAC(result.address_components, 'locality').long_name,
|
|
38
|
+
subLocality: findAC(result.address_components, 'sublocality').long_name,
|
|
39
|
+
thoroughfare: findAC(result.address_components, 'route').long_name,
|
|
40
|
+
subThoroughfare: findAC(result.address_components, 'street_number').long_name,
|
|
41
|
+
areasOfInterest: [],
|
|
42
|
+
};
|
|
43
|
+
})
|
|
44
|
+
.slice(0, options.maxResults || 1),
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async forwardGeocode(options) {
|
|
49
|
+
if (!options.apiKey) {
|
|
50
|
+
throw new Error('apiKey is required for web');
|
|
51
|
+
}
|
|
52
|
+
const params = Object.assign(Object.assign({ address: options.addressString, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: 'street_address' });
|
|
53
|
+
return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)
|
|
54
|
+
.then((response) => response.json())
|
|
55
|
+
.then((data) => {
|
|
56
|
+
return {
|
|
57
|
+
addresses: data.results
|
|
58
|
+
.map((result) => {
|
|
59
|
+
// transform the response in Address[]
|
|
60
|
+
// use the result from google geocoder and transform it in Address
|
|
61
|
+
return {
|
|
62
|
+
latitude: result.geometry.location.lat,
|
|
63
|
+
longitude: result.geometry.location.lng,
|
|
64
|
+
countryCode: findAC(result.address_components, 'country').short_name,
|
|
65
|
+
countryName: findAC(result.address_components, 'country').long_name,
|
|
66
|
+
postalCode: findAC(result.address_components, 'postal_code').long_name,
|
|
67
|
+
administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,
|
|
68
|
+
subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,
|
|
69
|
+
locality: findAC(result.address_components, 'locality').long_name,
|
|
70
|
+
subLocality: findAC(result.address_components, 'sublocality').long_name,
|
|
71
|
+
thoroughfare: findAC(result.address_components, 'route').long_name,
|
|
72
|
+
subThoroughfare: findAC(result.address_components, 'street_number').long_name,
|
|
73
|
+
areasOfInterest: [],
|
|
74
|
+
};
|
|
75
|
+
})
|
|
76
|
+
.slice(0, options.maxResults || 1),
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
async getPluginVersion() {
|
|
81
|
+
return { version: 'web' };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
86
|
+
__proto__: null,
|
|
87
|
+
NativeGeocoderWeb: NativeGeocoderWeb
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
exports.NativeGeocoder = NativeGeocoder;
|
|
91
|
+
|
|
92
|
+
return exports;
|
|
93
|
+
|
|
94
|
+
})({}, capacitorExports);
|
|
95
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +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';\nconst findAC = (address_components, type) => {\n return (address_components.find((component) => component.types.includes(type)) || {\n long_name: '',\n short_name: '',\n types: [],\n });\n};\nexport class NativeGeocoderWeb extends WebPlugin {\n async reverseGeocode(options) {\n if (!options.apiKey) {\n throw new Error('apiKey is required for web');\n }\n const params = Object.assign(Object.assign({ latlng: `${options.latitude},${options.longitude}`, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: options.resultType || 'street_address' });\n return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)\n .then((response) => response.json())\n .then((data) => {\n return {\n addresses: data.results\n .map((result) => {\n // transform the response in Address[]\n // use the result from google geocoder and transform it in Address\n return {\n latitude: result.geometry.location.lat,\n longitude: result.geometry.location.lng,\n countryCode: findAC(result.address_components, 'country').short_name,\n countryName: findAC(result.address_components, 'country').long_name,\n postalCode: findAC(result.address_components, 'postal_code').long_name,\n administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,\n subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,\n locality: findAC(result.address_components, 'locality').long_name,\n subLocality: findAC(result.address_components, 'sublocality').long_name,\n thoroughfare: findAC(result.address_components, 'route').long_name,\n subThoroughfare: findAC(result.address_components, 'street_number').long_name,\n areasOfInterest: [],\n };\n })\n .slice(0, options.maxResults || 1),\n };\n });\n }\n async forwardGeocode(options) {\n if (!options.apiKey) {\n throw new Error('apiKey is required for web');\n }\n const params = Object.assign(Object.assign({ address: options.addressString, key: options.apiKey }, (options.defaultLocale && { language: options.defaultLocale })), { result_type: 'street_address' });\n return fetch(`https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(params).toString()}`)\n .then((response) => response.json())\n .then((data) => {\n return {\n addresses: data.results\n .map((result) => {\n // transform the response in Address[]\n // use the result from google geocoder and transform it in Address\n return {\n latitude: result.geometry.location.lat,\n longitude: result.geometry.location.lng,\n countryCode: findAC(result.address_components, 'country').short_name,\n countryName: findAC(result.address_components, 'country').long_name,\n postalCode: findAC(result.address_components, 'postal_code').long_name,\n administrativeArea: findAC(result.address_components, 'administrative_area_level_1').long_name,\n subAdministrativeArea: findAC(result.address_components, 'administrative_area_level_2').long_name,\n locality: findAC(result.address_components, 'locality').long_name,\n subLocality: findAC(result.address_components, 'sublocality').long_name,\n thoroughfare: findAC(result.address_components, 'route').long_name,\n subThoroughfare: findAC(result.address_components, 'street_number').long_name,\n areasOfInterest: [],\n };\n })\n .slice(0, options.maxResults || 1),\n };\n });\n }\n async getPluginVersion() {\n return { version: 'web' };\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;IACL,CAAC;IACM,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,CA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BAAqB;IACrB,gBAAgB,CAAC;IACjB,qBAAqB,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC;IACtD,aAAa;IACb,QAAQ,CAAC,CAAC;IACV,IAAI;IACJ,IAAI,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;IACjC,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
import CoreLocation
|
|
4
|
+
|
|
5
|
+
struct NativeGeocoderError {
|
|
6
|
+
var message: String
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
struct NativeGeocoderOptions: Decodable {
|
|
10
|
+
var useLocale: Bool = true
|
|
11
|
+
var defaultLocale: String?
|
|
12
|
+
var maxResults: Int = 1
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@objc public class NativeGeocoder: NSObject {
|
|
16
|
+
|
|
17
|
+
typealias ReverseGeocodeCompletionHandler = ([JSObject]?, NativeGeocoderError?) -> Void
|
|
18
|
+
typealias ForwardGeocodeCompletionHandler = ([JSObject]?, NativeGeocoderError?) -> Void
|
|
19
|
+
private static let MAX_RESULTS_COUNT = 5
|
|
20
|
+
|
|
21
|
+
func reverseGeocode(latitude: Double, longitude: Double, call: CAPPluginCall) {
|
|
22
|
+
if CLGeocoder().isGeocoding {
|
|
23
|
+
call.reject("Geocoder is busy. Please try again later.")
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let location = CLLocation(latitude: latitude, longitude: longitude)
|
|
28
|
+
var options = NativeGeocoderOptions(useLocale: true, defaultLocale: nil, maxResults: 1)
|
|
29
|
+
options.useLocale = call.getBool("useLocale") ?? true
|
|
30
|
+
options.defaultLocale = call.getString("defaultLocale")
|
|
31
|
+
options.maxResults = call.getInt("maxResults") ?? 1
|
|
32
|
+
|
|
33
|
+
reverseGeocodeLocationHandler(location, options: options, completionHandler: { (resultObj, error) in
|
|
34
|
+
if let error = error {
|
|
35
|
+
call.reject(error.message)
|
|
36
|
+
} else {
|
|
37
|
+
call.resolve(["addresses": resultObj])
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private func reverseGeocodeLocationHandler(_ location: CLLocation, options: NativeGeocoderOptions, completionHandler: @escaping ReverseGeocodeCompletionHandler) {
|
|
43
|
+
let geocoderOptions = getNativeGeocoderOptions(from: options)
|
|
44
|
+
|
|
45
|
+
var locale: Locale?
|
|
46
|
+
if let defaultLocaleString = geocoderOptions.defaultLocale {
|
|
47
|
+
locale = Locale.init(identifier: defaultLocaleString)
|
|
48
|
+
} else if geocoderOptions.useLocale == false {
|
|
49
|
+
locale = Locale.init(identifier: "en_US")
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
CLGeocoder().reverseGeocodeLocation(location, preferredLocale: locale, completionHandler: { [weak self] (placemarks, error) in
|
|
53
|
+
self?.createReverseGeocodeResult(placemarks, error, maxResults: geocoderOptions.maxResults, completionHandler: { (resultObj, error) in
|
|
54
|
+
completionHandler(resultObj, error)
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private func createReverseGeocodeResult(_ placemarks: [CLPlacemark]?, _ error: Error?, maxResults: Int, completionHandler: @escaping ReverseGeocodeCompletionHandler) {
|
|
60
|
+
guard error == nil else {
|
|
61
|
+
completionHandler(nil, NativeGeocoderError(message: "CLGeocoder:reverseGeocodeLocation Error"))
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if let placemarks = placemarks {
|
|
66
|
+
let maxResultObjects = placemarks.count >= maxResults ? maxResults : placemarks.count
|
|
67
|
+
var resultObj = [JSObject]()
|
|
68
|
+
|
|
69
|
+
for i in 0..<maxResultObjects {
|
|
70
|
+
let placemark = makePosition(placemarks[i])
|
|
71
|
+
resultObj.append(placemark)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
completionHandler(resultObj, nil)
|
|
75
|
+
} else {
|
|
76
|
+
completionHandler(nil, NativeGeocoderError(message: "Cannot get an address"))
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
func forwardGeocode(address: String, call: CAPPluginCall) {
|
|
81
|
+
|
|
82
|
+
if CLGeocoder().isGeocoding {
|
|
83
|
+
call.reject("Geocoder is busy. Please try again later.")
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
var options = NativeGeocoderOptions(useLocale: true, defaultLocale: nil, maxResults: 1)
|
|
88
|
+
options.useLocale = call.getBool("useLocale") ?? true
|
|
89
|
+
options.defaultLocale = call.getString("defaultLocale")
|
|
90
|
+
options.maxResults = call.getInt("maxResults") ?? 1
|
|
91
|
+
|
|
92
|
+
forwardGeocodeHandler(address, options: options, completionHandler: { (resultObj, error) in
|
|
93
|
+
if let error = error as? CLError {
|
|
94
|
+
var msg = "CLGeocoder:forwardGeocodeLocation Error"
|
|
95
|
+
switch error.code {
|
|
96
|
+
case .locationUnknown:
|
|
97
|
+
msg = "locationUnknown: location manager was unable to obtain a location value right now."
|
|
98
|
+
case .denied:
|
|
99
|
+
msg = "denied: user denied access to the location service."
|
|
100
|
+
case .promptDeclined:
|
|
101
|
+
msg = "promptDeclined: user didn’t grant the requested temporary authorization."
|
|
102
|
+
case .network:
|
|
103
|
+
msg = "network: network was unavailable or a network error occurred."
|
|
104
|
+
case .headingFailure:
|
|
105
|
+
msg = "headingFailure: heading could not be determined."
|
|
106
|
+
case .rangingUnavailable:
|
|
107
|
+
msg = "rangingUnavailable: ranging is disabled."
|
|
108
|
+
case .rangingFailure:
|
|
109
|
+
msg = "rangingFailure: a general ranging error occurred."
|
|
110
|
+
default: break
|
|
111
|
+
}
|
|
112
|
+
print(msg)
|
|
113
|
+
call.reject(msg)
|
|
114
|
+
} else {
|
|
115
|
+
call.resolve(["addresses": resultObj])
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
func forwardGeocodeHandler(_ address: String, options: NativeGeocoderOptions, completionHandler: @escaping ForwardGeocodeCompletionHandler) {
|
|
121
|
+
let geocoderOptions = getNativeGeocoderOptions(from: options)
|
|
122
|
+
|
|
123
|
+
var locale: Locale?
|
|
124
|
+
if let defaultLocaleString = geocoderOptions.defaultLocale {
|
|
125
|
+
locale = Locale.init(identifier: defaultLocaleString)
|
|
126
|
+
} else if geocoderOptions.useLocale == false {
|
|
127
|
+
locale = Locale.init(identifier: "en_US")
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
CLGeocoder().geocodeAddressString(address, in: nil, preferredLocale: locale, completionHandler: { [weak self] (placemarks, error) in
|
|
131
|
+
self?.createForwardGeocodeResult(placemarks, error, maxResults: geocoderOptions.maxResults, completionHandler: { (resultObj, error) in
|
|
132
|
+
completionHandler(resultObj, error)
|
|
133
|
+
})
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private func makePosition(_ placemark: CLPlacemark) -> JSObject {
|
|
138
|
+
var ret = JSObject()
|
|
139
|
+
ret["latitude"] = placemark.location?.coordinate.latitude ?? ""
|
|
140
|
+
ret["longitude"] = placemark.location?.coordinate.longitude ?? ""
|
|
141
|
+
ret["countryCode"] = placemark.isoCountryCode ?? ""
|
|
142
|
+
ret["countryName"] = placemark.country ?? ""
|
|
143
|
+
ret["postalCode"] = placemark.postalCode ?? ""
|
|
144
|
+
ret["administrativeArea"] = placemark.administrativeArea ?? ""
|
|
145
|
+
ret["subAdministrativeArea"] = placemark.subAdministrativeArea ?? ""
|
|
146
|
+
ret["locality"] = placemark.locality ?? ""
|
|
147
|
+
ret["subLocality"] = placemark.subLocality ?? ""
|
|
148
|
+
ret["thoroughfare"] = placemark.thoroughfare ?? ""
|
|
149
|
+
ret["subThoroughfare"] = placemark.subThoroughfare ?? ""
|
|
150
|
+
ret["areasOfInterest"] = placemark.areasOfInterest ?? []
|
|
151
|
+
return ret
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private func createForwardGeocodeResult(_ placemarks: [CLPlacemark]?, _ error: Error?, maxResults: Int, completionHandler: @escaping ForwardGeocodeCompletionHandler) {
|
|
155
|
+
guard error == nil else {
|
|
156
|
+
completionHandler(nil, NativeGeocoderError(message: "CLGeocoder:geocodeAddressString Error"))
|
|
157
|
+
return
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if let placemarks = placemarks {
|
|
161
|
+
let maxResultObjects = placemarks.count >= maxResults ? maxResults : placemarks.count
|
|
162
|
+
var resultObj = [JSObject]()
|
|
163
|
+
|
|
164
|
+
for i in 0..<maxResultObjects {
|
|
165
|
+
if let latitude = placemarks[i].location?.coordinate.latitude,
|
|
166
|
+
let longitude = placemarks[i].location?.coordinate.longitude {
|
|
167
|
+
let placemark = makePosition(placemarks[i])
|
|
168
|
+
resultObj.append(placemark)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if resultObj.count == 0 {
|
|
173
|
+
completionHandler(nil, NativeGeocoderError(message: "Cannot get latitude and/or longitude"))
|
|
174
|
+
} else {
|
|
175
|
+
completionHandler(resultObj, nil)
|
|
176
|
+
}
|
|
177
|
+
} else {
|
|
178
|
+
completionHandler(nil, NativeGeocoderError(message: "Cannot find a location"))
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// MARK: - Helper
|
|
183
|
+
private func getNativeGeocoderOptions(from options: NativeGeocoderOptions) -> NativeGeocoderOptions {
|
|
184
|
+
var geocoderOptions = NativeGeocoderOptions()
|
|
185
|
+
geocoderOptions.useLocale = options.useLocale
|
|
186
|
+
geocoderOptions.defaultLocale = options.defaultLocale
|
|
187
|
+
if options.maxResults > 0 {
|
|
188
|
+
geocoderOptions.maxResults = options.maxResults > NativeGeocoder.MAX_RESULTS_COUNT ? NativeGeocoder.MAX_RESULTS_COUNT : options.maxResults
|
|
189
|
+
} else {
|
|
190
|
+
geocoderOptions.maxResults = 1
|
|
191
|
+
}
|
|
192
|
+
return geocoderOptions
|
|
193
|
+
}
|
|
194
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Please read the Capacitor iOS Plugin Development Guide
|
|
6
|
+
* here: https://capacitorjs.com/docs/plugins/ios
|
|
7
|
+
*/
|
|
8
|
+
@objc(NativeGeocoderPlugin)
|
|
9
|
+
public class NativeGeocoderPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
10
|
+
private let pluginVersion: String = "8.0.32"
|
|
11
|
+
public let identifier = "NativeGeocoderPlugin"
|
|
12
|
+
public let jsName = "NativeGeocoder"
|
|
13
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
14
|
+
CAPPluginMethod(name: "reverseGeocode", returnType: CAPPluginReturnPromise),
|
|
15
|
+
CAPPluginMethod(name: "forwardGeocode", returnType: CAPPluginReturnPromise),
|
|
16
|
+
CAPPluginMethod(name: "getPluginVersion", returnType: CAPPluginReturnPromise)
|
|
17
|
+
]
|
|
18
|
+
private let implementation = NativeGeocoder()
|
|
19
|
+
|
|
20
|
+
@objc func reverseGeocode(_ call: CAPPluginCall) {
|
|
21
|
+
guard let latitude = call.getDouble("latitude") else {
|
|
22
|
+
call.reject("Missing latitude")
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
guard let longitude = call.getDouble("longitude") else {
|
|
26
|
+
call.reject("Missing longitude")
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
implementation.reverseGeocode(latitude: latitude, longitude: longitude, call: call)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@objc func forwardGeocode(_ call: CAPPluginCall) {
|
|
33
|
+
guard let addressString = call.getString("addressString") else {
|
|
34
|
+
call.reject("Missing addressString")
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
implementation.forwardGeocode(address: addressString, call: call)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@objc func getPluginVersion(_ call: CAPPluginCall) {
|
|
41
|
+
call.resolve(["version": self.pluginVersion])
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import XCTest
|
|
2
|
+
@testable import Plugin
|
|
3
|
+
|
|
4
|
+
class NativeGeocoderTests: XCTestCase {
|
|
5
|
+
|
|
6
|
+
func testEcho() {
|
|
7
|
+
// This is an example of a functional test case for a plugin.
|
|
8
|
+
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
|
9
|
+
|
|
10
|
+
let implementation = NativeGeocoder()
|
|
11
|
+
let value = "Hello, World!"
|
|
12
|
+
let result = implementation.echo(value)
|
|
13
|
+
|
|
14
|
+
XCTAssertEqual(value, result)
|
|
15
|
+
}
|
|
16
|
+
}
|