@capgo/nativegeocoder 0.1.2 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,6 +9,32 @@ npm install @capgo/nativegeocoder
9
9
  npx cap sync
10
10
  ```
11
11
 
12
+ then import this into your code:
13
+
14
+ ```javascript
15
+ import { NativeGeocoder } from '@capgo/nativegeocoder';
16
+ ```
17
+
18
+ ## iOS
19
+
20
+ Apple requires privacy descriptions to be specified in `Info.plist` for location information:
21
+
22
+ - `NSLocationAlwaysUsageDescription` (`Privacy - Location Always Usage Description`)
23
+ - `NSLocationWhenInUseUsageDescription` (`Privacy - Location When In Use Usage Description`)
24
+
25
+ Read about [Configuring `Info.plist`](https://capacitorjs.com/docs/ios/configuration#configuring-infoplist) in the [iOS Guide](https://capacitorjs.com/docs/ios) for more information on setting iOS permissions in Xcode
26
+
27
+ ## Android
28
+
29
+ This API requires the following permissions be added to your `AndroidManifest.xml`:
30
+
31
+ ```xml
32
+ <!-- Geolocation API -->
33
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
34
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
35
+ <uses-feature android:name="android.hardware.location.gps" />
36
+ ```
37
+
12
38
  ## API
13
39
 
14
40
  <docgen-index>
@@ -1,4 +1,5 @@
1
1
  import Foundation
2
+ import Capacitor
2
3
  import CoreLocation
3
4
 
4
5
  struct NativeGeocoderResult: Encodable {
@@ -32,8 +33,7 @@ struct NativeGeocoderOptions: Decodable {
32
33
  typealias ForwardGeocodeCompletionHandler = ([NativeGeocoderResult]?, NativeGeocoderError?) -> Void
33
34
  private static let MAX_RESULTS_COUNT = 5
34
35
 
35
- // MARK: - REVERSE GEOCODE
36
- @objc(reverseGeocode:) func reverseGeocode(latitude: Double, longitude: Double, call: CAPPluginCall) {
36
+ func reverseGeocode(latitude: Double, longitude: Double, call: CAPPluginCall) {
37
37
  if (CLGeocoder().isGeocoding) {
38
38
  call.reject("Geocoder is busy. Please try again later.")
39
39
  return
@@ -41,9 +41,9 @@ struct NativeGeocoderOptions: Decodable {
41
41
 
42
42
  let location = CLLocation(latitude: latitude, longitude: longitude)
43
43
  var options = NativeGeocoderOptions(useLocale: true, defaultLocale: nil, maxResults: 1)
44
- options.useLocale = call.getBoolean("useLocale") ?? true
45
- options.defaultLocale = call.getString()
46
- options.maxResults = call.getNumber() ?? 1
44
+ options.useLocale = call.getBool("useLocale") ?? true
45
+ options.defaultLocale = call.getString("defaultLocale")
46
+ options.maxResults = call.getInt("maxResults") ?? 1
47
47
 
48
48
  reverseGeocodeLocationHandler(location, options: options, completionHandler: { [weak self] (resultObj, error) in
49
49
  if let error = error {
@@ -130,8 +130,7 @@ struct NativeGeocoderOptions: Decodable {
130
130
  }
131
131
 
132
132
 
133
- // MARK: - FORWARD GEOCODE
134
- @objc(forwardGeocode:)func forwardGeocode(address: String, call: CAPPluginCall) {
133
+ func forwardGeocode(address: String, call: CAPPluginCall) {
135
134
 
136
135
  if (CLGeocoder().isGeocoding) {
137
136
  call.reject("Geocoder is busy. Please try again later.")
@@ -139,9 +138,9 @@ struct NativeGeocoderOptions: Decodable {
139
138
  }
140
139
 
141
140
  var options = NativeGeocoderOptions(useLocale: true, defaultLocale: nil, maxResults: 1)
142
- options.useLocale = call.getBoolean("useLocale") ?? true
143
- options.defaultLocale = call.getString()
144
- options.maxResults = call.getNumber() ?? 1
141
+ options.useLocale = call.getBool("useLocale") ?? true
142
+ options.defaultLocale = call.getString("defaultLocale")
143
+ options.maxResults = call.getInt("maxResults") ?? 1
145
144
 
146
145
  forwardGeocodeHandler(address, options: options, completionHandler: { [weak self] (resultObj, error) in
147
146
  if let error = error {
@@ -10,14 +10,6 @@ public class NativeGeocoderPlugin: CAPPlugin {
10
10
  private let implementation = NativeGeocoder()
11
11
 
12
12
  @objc func reverseGeocode(_ call: CAPPluginCall) {
13
- guard let addressString = call.getString("addressString") else {
14
- call.reject("Missing addressString")
15
- return
16
- }
17
- implementation.reverseGeocode(addressString: addressString, call: call)
18
- }
19
-
20
- @objc func forwardGeocode(_ call: CAPPluginCall) {
21
13
  guard let latitude = call.getDouble("latitude") else {
22
14
  call.reject("Missing latitude")
23
15
  return
@@ -26,6 +18,14 @@ public class NativeGeocoderPlugin: CAPPlugin {
26
18
  call.reject("Missing longitude")
27
19
  return
28
20
  }
29
- implementation.forwardGeocode(latitude: latitude, longitude: longitude, call: call)
21
+ implementation.reverseGeocode(latitude: latitude, longitude: longitude, call: call)
22
+ }
23
+
24
+ @objc func forwardGeocode(_ call: CAPPluginCall) {
25
+ guard let addressString = call.getString("addressString") else {
26
+ call.reject("Missing addressString")
27
+ return
28
+ }
29
+ implementation.forwardGeocode(address: addressString, call: call)
30
30
  }
31
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/nativegeocoder",
3
- "version": "0.1.2",
3
+ "version": "0.1.5",
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",