@capgo/nativegeocoder 1.0.21 → 6.0.0

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.
@@ -19,10 +19,10 @@ apply plugin: 'com.android.library'
19
19
 
20
20
  android {
21
21
  namespace "ee.forgr.capacitor_nativegeocoder"
22
- compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 33
22
+ compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
23
23
  defaultConfig {
24
24
  minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
25
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 33
25
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
26
26
  versionCode 1
27
27
  versionName "1.0"
28
28
  testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -288,8 +288,10 @@ public class NativeGeocoder {
288
288
  geocoderOptions.maxResults = options.getInt("maxResults", 1);
289
289
  if (geocoderOptions.maxResults > 0) {
290
290
  int MAX_RESULTS_COUNT = 5;
291
- geocoderOptions.maxResults =
292
- Math.min(geocoderOptions.maxResults, MAX_RESULTS_COUNT);
291
+ geocoderOptions.maxResults = Math.min(
292
+ geocoderOptions.maxResults,
293
+ MAX_RESULTS_COUNT
294
+ );
293
295
  } else {
294
296
  geocoderOptions.maxResults = 1;
295
297
  }
@@ -319,19 +321,24 @@ public class NativeGeocoder {
319
321
  locale = Locale.forLanguageTag(geocoderOptions.defaultLocale);
320
322
  } else {
321
323
  String[] parts = geocoderOptions.defaultLocale.split("[-_]", -1);
322
- if (parts.length == 1) locale = new Locale(parts[0]); else if (
324
+ if (parts.length == 1) locale = new Locale(parts[0]);
325
+ else if (
323
326
  parts.length == 2 || (parts.length == 3 && parts[2].startsWith("#"))
324
- ) locale = new Locale(parts[0], parts[1]); else locale =
325
- new Locale(parts[0], parts[1], parts[2]);
327
+ ) locale = new Locale(parts[0], parts[1]);
328
+ else locale = new Locale(parts[0], parts[1], parts[2]);
326
329
  }
327
330
  geocoder = new Geocoder(context.getApplicationContext(), locale);
328
331
  } else {
329
332
  if (geocoderOptions.useLocale) {
330
- geocoder =
331
- new Geocoder(context.getApplicationContext(), Locale.getDefault());
333
+ geocoder = new Geocoder(
334
+ context.getApplicationContext(),
335
+ Locale.getDefault()
336
+ );
332
337
  } else {
333
- geocoder =
334
- new Geocoder(context.getApplicationContext(), Locale.ENGLISH);
338
+ geocoder = new Geocoder(
339
+ context.getApplicationContext(),
340
+ Locale.ENGLISH
341
+ );
335
342
  }
336
343
  }
337
344
  return geocoder;
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AA2C5C,MAAM,MAAM,GAAG,CACb,kBAAsC,EACtC,IAAY,EACM,EAAE;IACpB,OAAO,CACL,kBAAkB,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI;QACxE,SAAS,EAAE,EAAE;QACb,UAAU,EAAE,EAAE;QACd,KAAK,EAAE,EAAE;KACV,CACF,CAAC;AACJ,CAAC,CAAC;AACF,MAAM,OAAO,iBACX,SAAQ,SAAS;IAGjB,KAAK,CAAC,cAAc,CAClB,OAAuB;QAEvB,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YACnB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;SAC/C;QACD,MAAM,MAAM,iCACV,MAAM,EAAE,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,SAAS,EAAE,EAClD,GAAG,EAAE,OAAO,CAAC,MAAM,IAChB,CAAC,OAAO,CAAC,aAAa,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,a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AU,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,aAAa,CAAC;6BACzD,SAAS;wBACZ,kBAAkB,EAAE,MAAM,CACxB,MAAM,CAAC,kBAAkB,EACzB,6BAA6B,CAC9B,CAAC,SAAS;wBACX,qBAAqB,EAAE,MAAM,CAC3B,MAAM,CAAC,kBAAkB,EACzB,6BAA6B,CAC9B,CAAC,SAAS;wBACX,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,UAAU,CAAC;6BACpD,SAAS;wBACZ,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,aAAa,CAAC;6BAC1D,SAAS;wBACZ,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,OAAO,CAAC;6BACrD,SAAS;wBACZ,eAAe,EAAE,MAAM,CACrB,MAAM,CAAC,kBAAkB,EACzB,eAAe,CAChB,CAAC,SAAS;wBACX,eAAe,EAAE,EAAE;qBACpB,CAAC;gBACJ,CAAC,CAAC;qBACD,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC;aACrC,CAAC;QACJ,CAAC,CAAC,CAAC;IACP,CAAC;CACF","sourcesContent":["import { WebPlugin } from \"@capacitor/core\";\n\nimport type {\n NativeGeocoderPlugin,\n ReverseOptions,\n ForwardOptions,\n Address,\n} from \"./definitions\";\n\ninterface AddressComponent {\n long_name: string;\n short_name: string;\n types: string[];\n}\ninterface GeocoderResult {\n address_components: AddressComponent[];\n formatted_address: string;\n geometry: {\n location: {\n lat: number;\n lng: number;\n };\n location_type: string;\n viewport: {\n northeast: {\n lat: number;\n lng: number;\n };\n southwest: {\n lat: number;\n lng: number;\n };\n };\n };\n}\ninterface GeocoderPayload {\n plus_code: {\n compound_code: string;\n global_code: string;\n };\n results: GeocoderResult[];\n}\n\nconst findAC = (\n address_components: AddressComponent[],\n type: string\n): AddressComponent => {\n return (\n address_components.find((component) => component.types.includes(type)) || {\n long_name: \"\",\n short_name: \"\",\n types: [],\n }\n );\n};\nexport class NativeGeocoderWeb\n extends WebPlugin\n implements NativeGeocoderPlugin\n{\n async reverseGeocode(\n options: ReverseOptions\n ): Promise<{ addresses: 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: \"street_address\",\n };\n return fetch(\n `https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(\n params\n ).toString()}`\n )\n .then((response) => response.json())\n .then((data: GeocoderPayload): { addresses: 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\")\n .short_name,\n countryName: findAC(result.address_components, \"country\")\n .long_name,\n postalCode: findAC(result.address_components, \"postal_code\")\n .long_name,\n administrativeArea: findAC(\n result.address_components,\n \"administrative_area_level_1\"\n ).long_name,\n subAdministrativeArea: findAC(\n result.address_components,\n \"administrative_area_level_2\"\n ).long_name,\n locality: findAC(result.address_components, \"locality\")\n .long_name,\n subLocality: findAC(result.address_components, \"sublocality\")\n .long_name,\n thoroughfare: findAC(result.address_components, \"route\")\n .long_name,\n subThoroughfare: findAC(\n result.address_components,\n \"street_number\"\n ).long_name,\n areasOfInterest: [],\n };\n })\n .slice(0, options.maxResults || 1),\n };\n });\n }\n async forwardGeocode(\n options: ForwardOptions\n ): Promise<{ addresses: 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(\n `https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(\n params\n ).toString()}`\n )\n .then((response) => response.json())\n .then((data: GeocoderPayload): { addresses: 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\")\n .short_name,\n countryName: findAC(result.address_components, \"country\")\n .long_name,\n postalCode: findAC(result.address_components, \"postal_code\")\n .long_name,\n administrativeArea: findAC(\n result.address_components,\n \"administrative_area_level_1\"\n ).long_name,\n subAdministrativeArea: findAC(\n result.address_components,\n \"administrative_area_level_2\"\n ).long_name,\n locality: findAC(result.address_components, \"locality\")\n .long_name,\n subLocality: findAC(result.address_components, \"sublocality\")\n .long_name,\n thoroughfare: findAC(result.address_components, \"route\")\n .long_name,\n subThoroughfare: findAC(\n result.address_components,\n \"street_number\"\n ).long_name,\n areasOfInterest: [],\n };\n })\n .slice(0, options.maxResults || 1),\n };\n });\n }\n}\n"]}
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AA2C5C,MAAM,MAAM,GAAG,CACb,kBAAsC,EACtC,IAAY,EACM,EAAE;IACpB,OAAO,CACL,kBAAkB,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI;QACxE,SAAS,EAAE,EAAE;QACb,UAAU,EAAE,EAAE;QACd,KAAK,EAAE,EAAE;KACV,CACF,CAAC;AACJ,CAAC,CAAC;AACF,MAAM,OAAO,iBACX,SAAQ,SAAS;IAGjB,KAAK,CAAC,cAAc,CAClB,OAAuB;QAEvB,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAChD,CAAC;QACD,MAAM,MAAM,iCACV,MAAM,EAAE,GAAG,OAAO,CAA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MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,SAAS,CAAC;6BACtD,UAAU;wBACb,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,SAAS,CAAC;6BACtD,SAAS;wBACZ,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,aAAa,CAAC;6BACzD,SAAS;wBACZ,kBAAkB,EAAE,MAAM,CACxB,MAAM,CAAC,kBAAkB,EACzB,6BAA6B,CAC9B,CAAC,SAAS;wBACX,qBAAqB,EAAE,MAAM,CAC3B,MAAM,CAAC,kBAAkB,EACzB,6BAA6B,CAC9B,CAAC,SAAS;wBACX,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,UAAU,CAAC;6BACpD,SAAS;wBACZ,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,aAAa,CAAC;6BAC1D,SAAS;wBACZ,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,OAAO,CAAC;6BACrD,SAAS;wBACZ,eAAe,EAAE,MAAM,CACrB,MAAM,CAAC,kBAAkB,EACzB,eAAe,CAChB,CAAC,SAAS;wBACX,eAAe,EAAE,EAAE;qBACpB,CAAC;gBACJ,CAAC,CAAC;qBACD,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC;aACrC,CAAC;QACJ,CAAC,CAAC,CAAC;IACP,CAAC;CACF","sourcesContent":["import { WebPlugin } from \"@capacitor/core\";\n\nimport type {\n NativeGeocoderPlugin,\n ReverseOptions,\n ForwardOptions,\n Address,\n} from \"./definitions\";\n\ninterface AddressComponent {\n long_name: string;\n short_name: string;\n types: string[];\n}\ninterface GeocoderResult {\n address_components: AddressComponent[];\n formatted_address: string;\n geometry: {\n location: {\n lat: number;\n lng: number;\n };\n location_type: string;\n viewport: {\n northeast: {\n lat: number;\n lng: number;\n };\n southwest: {\n lat: number;\n lng: number;\n };\n };\n };\n}\ninterface GeocoderPayload {\n plus_code: {\n compound_code: string;\n global_code: string;\n };\n results: GeocoderResult[];\n}\n\nconst findAC = (\n address_components: AddressComponent[],\n type: string,\n): AddressComponent => {\n return (\n address_components.find((component) => component.types.includes(type)) || {\n long_name: \"\",\n short_name: \"\",\n types: [],\n }\n );\n};\nexport class NativeGeocoderWeb\n extends WebPlugin\n implements NativeGeocoderPlugin\n{\n async reverseGeocode(\n options: ReverseOptions,\n ): Promise<{ addresses: 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: \"street_address\",\n };\n return fetch(\n `https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(\n params,\n ).toString()}`,\n )\n .then((response) => response.json())\n .then((data: GeocoderPayload): { addresses: 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\")\n .short_name,\n countryName: findAC(result.address_components, \"country\")\n .long_name,\n postalCode: findAC(result.address_components, \"postal_code\")\n .long_name,\n administrativeArea: findAC(\n result.address_components,\n \"administrative_area_level_1\",\n ).long_name,\n subAdministrativeArea: findAC(\n result.address_components,\n \"administrative_area_level_2\",\n ).long_name,\n locality: findAC(result.address_components, \"locality\")\n .long_name,\n subLocality: findAC(result.address_components, \"sublocality\")\n .long_name,\n thoroughfare: findAC(result.address_components, \"route\")\n .long_name,\n subThoroughfare: findAC(\n result.address_components,\n \"street_number\",\n ).long_name,\n areasOfInterest: [],\n };\n })\n .slice(0, options.maxResults || 1),\n };\n });\n }\n async forwardGeocode(\n options: ForwardOptions,\n ): Promise<{ addresses: 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(\n `https://maps.googleapis.com/maps/api/geocode/json?${new URLSearchParams(\n params,\n ).toString()}`,\n )\n .then((response) => response.json())\n .then((data: GeocoderPayload): { addresses: 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\")\n .short_name,\n countryName: findAC(result.address_components, \"country\")\n .long_name,\n postalCode: findAC(result.address_components, \"postal_code\")\n .long_name,\n administrativeArea: findAC(\n result.address_components,\n \"administrative_area_level_1\",\n ).long_name,\n subAdministrativeArea: findAC(\n result.address_components,\n \"administrative_area_level_2\",\n ).long_name,\n locality: findAC(result.address_components, \"locality\")\n .long_name,\n subLocality: findAC(result.address_components, \"sublocality\")\n .long_name,\n thoroughfare: findAC(result.address_components, \"route\")\n .long_name,\n subThoroughfare: findAC(\n result.address_components,\n \"street_number\",\n ).long_name,\n areasOfInterest: [],\n };\n })\n .slice(0, options.maxResults || 1),\n };\n });\n }\n}\n"]}
@@ -99,29 +99,28 @@ struct NativeGeocoderOptions: Decodable {
99
99
  options.maxResults = call.getInt("maxResults") ?? 1
100
100
 
101
101
  forwardGeocodeHandler(address, options: options, completionHandler: { (resultObj, error) in
102
- if let error = error as? CLError {
102
+ if let error = error as? CLError {
103
103
  var msg = "CLGeocoder:forwardGeocodeLocation Error"
104
104
  switch error.code {
105
- case .locationUnknown:
106
- msg = "locationUnknown: location manager was unable to obtain a location value right now."
107
- case .denied:
108
- msg = "denied: user denied access to the location service."
109
- case .promptDeclined:
110
- msg = "promptDeclined: user didn’t grant the requested temporary authorization."
111
- case .network:
112
- msg = "network: network was unavailable or a network error occurred."
113
- case .headingFailure:
114
- msg = "headingFailure: heading could not be determined."
115
- case .rangingUnavailable:
116
- msg = "rangingUnavailable: ranging is disabled."
117
- case .rangingFailure:
118
- msg = "rangingFailure: a general ranging error occurred."
119
- default : break
105
+ case .locationUnknown:
106
+ msg = "locationUnknown: location manager was unable to obtain a location value right now."
107
+ case .denied:
108
+ msg = "denied: user denied access to the location service."
109
+ case .promptDeclined:
110
+ msg = "promptDeclined: user didn’t grant the requested temporary authorization."
111
+ case .network:
112
+ msg = "network: network was unavailable or a network error occurred."
113
+ case .headingFailure:
114
+ msg = "headingFailure: heading could not be determined."
115
+ case .rangingUnavailable:
116
+ msg = "rangingUnavailable: ranging is disabled."
117
+ case .rangingFailure:
118
+ msg = "rangingFailure: a general ranging error occurred."
119
+ default: break
120
120
  }
121
121
  print(msg)
122
122
  call.reject(msg)
123
- }
124
- else {
123
+ } else {
125
124
  call.resolve(["addresses": resultObj])
126
125
  }
127
126
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/nativegeocoder",
3
- "version": "1.0.21",
3
+ "version": "6.0.0",
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",
@@ -34,7 +34,7 @@
34
34
  "verify:web": "npm run build",
35
35
  "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
36
36
  "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --autocorrect --format",
37
- "eslint": "eslint . --ext ts",
37
+ "eslint": "eslint .",
38
38
  "prettier": "prettier --config .prettierrc.js \"**/*.{css,html,ts,js,java}\"",
39
39
  "swiftlint": "node-swiftlint",
40
40
  "docgen": "docgen --api NativeGeocoderPlugin --output-readme README.md --output-json dist/docs.json",
@@ -47,34 +47,31 @@
47
47
  "author": "Martin Donadieu <martindonadieu@gmail.com>",
48
48
  "license": "MIT",
49
49
  "devDependencies": {
50
- "@capacitor/android": "^5.0.3",
51
- "@capacitor/cli": "^5.0.3",
52
- "@capacitor/core": "^5.0.0",
53
- "@capacitor/docgen": "^0.2.1",
54
- "@capacitor/ios": "^5.0.3",
50
+ "@capacitor/android": "^6.0.0",
51
+ "@capacitor/cli": "^6.0.0",
52
+ "@capacitor/core": "^6.0.0",
53
+ "@capacitor/docgen": "^0.2.2",
54
+ "@capacitor/ios": "^6.0.0",
55
55
  "@ionic/eslint-config": "^0.3.0",
56
- "@ionic/prettier-config": "^3.0.0",
56
+ "@ionic/prettier-config": "^4.0.0",
57
57
  "@ionic/swiftlint-config": "^1.1.2",
58
- "@typescript-eslint/eslint-plugin": "^5.59.6",
59
- "@typescript-eslint/parser": "^5.59.6",
60
- "eslint": "^8.41.0",
61
- "eslint-plugin-import": "^2.27.5",
62
- "husky": "^8.0.3",
63
- "prettier": "^2.8.8",
64
- "prettier-plugin-java": "^2.1.0",
65
- "rimraf": "^5.0.1",
66
- "rollup": "^3.23.0",
58
+ "@typescript-eslint/eslint-plugin": "^7.8.0",
59
+ "@typescript-eslint/parser": "^7.8.0",
60
+ "eslint": "^9.1.1",
61
+ "eslint-plugin-import": "^2.29.1",
62
+ "husky": "^9.0.11",
63
+ "prettier": "^3.2.5",
64
+ "prettier-plugin-java": "^2.6.0",
65
+ "rimraf": "^5.0.5",
66
+ "rollup": "^4.17.1",
67
67
  "swiftlint": "^1.0.2",
68
- "typescript": "^5.0.4"
68
+ "typescript": "^5.4.5"
69
69
  },
70
70
  "peerDependencies": {
71
- "@capacitor/core": "^5.0.0"
71
+ "@capacitor/core": "^6.0.0"
72
72
  },
73
73
  "prettier": "@ionic/prettier-config",
74
74
  "swiftlint": "@ionic/swiftlint-config",
75
- "eslintConfig": {
76
- "extends": "@ionic/eslint-config/recommended"
77
- },
78
75
  "capacitor": {
79
76
  "ios": {
80
77
  "src": "ios"