expo-location 15.3.0 → 16.1.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.
package/CHANGELOG.md CHANGED
@@ -10,6 +10,16 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 16.1.0 — 2023-07-13
14
+
15
+ ### 🐛 Bug fixes
16
+
17
+ - Downgrade play-services-location to 20.0.0 to support react-native-maps. ([#23501](https://github.com/expo/expo/pull/23501) by [@gabrieldonadel](https://github.com/gabrieldonadel))
18
+
19
+ ## 16.0.0 — 2023-06-21
20
+
21
+ _This version does not introduce any user-facing changes._
22
+
13
23
  ## 15.3.0 — 2023-06-13
14
24
 
15
25
  ### 📚 3rd party library updates
@@ -23,6 +33,7 @@
23
33
  ### 💡 Others
24
34
 
25
35
  - On Android, removed use of deprecated `LocationRequest` constructor and replaced with `LocationRequest.Builder`. ([#22653](https://github.com/expo/expo/pull/22653) by [@alanjhughes](https://github.com/alanjhughes))
36
+ - Removed the Geocoding API service. ([#22830](https://github.com/expo/expo/pull/22830) by [@alanjhughes](https://github.com/alanjhughes))
26
37
 
27
38
  ## 15.2.0 — 2023-05-08
28
39
 
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
3
3
  apply plugin: 'maven-publish'
4
4
 
5
5
  group = 'host.exp.exponent'
6
- version = '15.3.0'
6
+ version = '16.1.0'
7
7
 
8
8
  buildscript {
9
9
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
@@ -67,7 +67,7 @@ android {
67
67
  minSdkVersion safeExtGet("minSdkVersion", 21)
68
68
  targetSdkVersion safeExtGet("targetSdkVersion", 33)
69
69
  versionCode 29
70
- versionName "15.3.0"
70
+ versionName "16.1.0"
71
71
  }
72
72
  lintOptions {
73
73
  abortOnError false
@@ -82,7 +82,7 @@ android {
82
82
  dependencies {
83
83
  implementation project(':expo-modules-core')
84
84
 
85
- api 'com.google.android.gms:play-services-location:21.0.1'
85
+ api 'com.google.android.gms:play-services-location:20.0.0'
86
86
 
87
87
  api('io.nlopez.smartlocation:library:3.3.3') {
88
88
  transitive = false
@@ -119,15 +119,16 @@ public class LocationHelpers {
119
119
  return heading;
120
120
  }
121
121
 
122
- public static LocationRequest.Builder prepareLocationRequest(Map<String, Object> options) {
122
+ public static LocationRequest prepareLocationRequest(Map<String, Object> options) {
123
123
  LocationParams locationParams = LocationHelpers.mapOptionsToLocationParams(options);
124
124
  int accuracy = LocationHelpers.getAccuracyFromOptions(options);
125
125
 
126
- return new LocationRequest.Builder(locationParams.getInterval())
127
- .setMinUpdateIntervalMillis(locationParams.getInterval())
128
- .setMaxUpdateDelayMillis(locationParams.getInterval())
129
- .setMinUpdateDistanceMeters(locationParams.getDistance())
130
- .setPriority(mapAccuracyToPriority(accuracy));
126
+ return new LocationRequest()
127
+ .setFastestInterval(locationParams.getInterval())
128
+ .setInterval(locationParams.getInterval())
129
+ .setMaxWaitTime(locationParams.getInterval())
130
+ .setSmallestDisplacement(locationParams.getDistance())
131
+ .setPriority(mapAccuracyToPriority(accuracy));
131
132
  }
132
133
 
133
134
  public static LocationParams mapOptionsToLocationParams(Map<String, Object> options) {
@@ -146,14 +147,14 @@ public class LocationHelpers {
146
147
  return locationParamsBuilder.build();
147
148
  }
148
149
 
149
- static void requestSingleLocation(final LocationModule locationModule, final LocationRequest.Builder locationRequest, final Promise promise) {
150
+ static void requestSingleLocation(final LocationModule locationModule, final LocationRequest locationRequest, final Promise promise) {
150
151
  // we want just one update
151
- locationRequest.setMaxUpdates(1);
152
+ locationRequest.setNumUpdates(1);
152
153
 
153
- locationModule.requestLocationUpdates(locationRequest.build(), null, new LocationRequestCallbacks() {
154
+ locationModule.requestLocationUpdates(locationRequest, null, new LocationRequestCallbacks() {
154
155
  @Override
155
156
  public void onLocationChanged(Location location) {
156
- promise.resolve(LocationHelpers.locationToBundle(location, Bundle.class));
157
+ promise.resolve(LocationHelpers.locationToBundle(location, Bundle.class));
157
158
  }
158
159
 
159
160
  @Override
@@ -275,7 +275,7 @@ public class LocationModule extends ExportedModule implements LifecycleEventList
275
275
  @ExpoMethod
276
276
  public void getCurrentPositionAsync(final Map<String, Object> options, final Promise promise) {
277
277
  // Read options
278
- final LocationRequest.Builder builder = LocationHelpers.prepareLocationRequest(options);
278
+ final LocationRequest locationRequest = LocationHelpers.prepareLocationRequest(options);
279
279
  boolean showUserSettingsDialog = !options.containsKey(SHOW_USER_SETTINGS_DIALOG_KEY) || (boolean) options.get(SHOW_USER_SETTINGS_DIALOG_KEY);
280
280
 
281
281
  // Check for permissions
@@ -285,12 +285,12 @@ public class LocationModule extends ExportedModule implements LifecycleEventList
285
285
  }
286
286
 
287
287
  if (LocationHelpers.hasNetworkProviderEnabled(mContext) || !showUserSettingsDialog) {
288
- LocationHelpers.requestSingleLocation(this, builder, promise);
288
+ LocationHelpers.requestSingleLocation(this, locationRequest, promise);
289
289
  } else {
290
290
  // Pending requests can ask the user to turn on improved accuracy mode in user's settings.
291
- addPendingLocationRequest(builder.build(), resultCode -> {
291
+ addPendingLocationRequest(locationRequest, resultCode -> {
292
292
  if (resultCode == Activity.RESULT_OK) {
293
- LocationHelpers.requestSingleLocation(LocationModule.this, builder, promise);
293
+ LocationHelpers.requestSingleLocation(LocationModule.this, locationRequest, promise);
294
294
  } else {
295
295
  promise.reject(new LocationSettingsUnsatisfiedException());
296
296
  }
@@ -336,16 +336,16 @@ public class LocationModule extends ExportedModule implements LifecycleEventList
336
336
  return;
337
337
  }
338
338
 
339
- final LocationRequest.Builder locationRequest = LocationHelpers.prepareLocationRequest(options);
339
+ final LocationRequest locationRequest = LocationHelpers.prepareLocationRequest(options);
340
340
  boolean showUserSettingsDialog = !options.containsKey(SHOW_USER_SETTINGS_DIALOG_KEY) || (boolean) options.get(SHOW_USER_SETTINGS_DIALOG_KEY);
341
341
 
342
342
  if (LocationHelpers.hasNetworkProviderEnabled(mContext) || !showUserSettingsDialog) {
343
- LocationHelpers.requestContinuousUpdates(this, locationRequest.build(), watchId, promise);
343
+ LocationHelpers.requestContinuousUpdates(this, locationRequest, watchId, promise);
344
344
  } else {
345
345
  // Pending requests can ask the user to turn on improved accuracy mode in user's settings.
346
- addPendingLocationRequest(locationRequest.build(), resultCode -> {
346
+ addPendingLocationRequest(locationRequest, resultCode -> {
347
347
  if (resultCode == Activity.RESULT_OK) {
348
- LocationHelpers.requestContinuousUpdates(LocationModule.this, locationRequest.build(), watchId, promise);
348
+ LocationHelpers.requestContinuousUpdates(LocationModule.this, locationRequest, watchId, promise);
349
349
  } else {
350
350
  promise.reject(new LocationSettingsUnsatisfiedException());
351
351
  }
@@ -443,9 +443,9 @@ public class LocationModule extends ExportedModule implements LifecycleEventList
443
443
  return;
444
444
  }
445
445
 
446
- LocationRequest.Builder locationRequest = LocationHelpers.prepareLocationRequest(new HashMap<>());
446
+ LocationRequest locationRequest = LocationHelpers.prepareLocationRequest(new HashMap<>());
447
447
 
448
- addPendingLocationRequest(locationRequest.build(), resultCode -> {
448
+ addPendingLocationRequest(locationRequest, resultCode -> {
449
449
  if (resultCode == Activity.RESULT_OK) {
450
450
  promise.resolve(null);
451
451
  } else {
@@ -181,7 +181,7 @@ public class LocationTaskConsumer extends TaskConsumer implements TaskConsumerIn
181
181
  return;
182
182
  }
183
183
 
184
- mLocationRequest = LocationHelpers.prepareLocationRequest(mTask.getOptions()).build();
184
+ mLocationRequest = LocationHelpers.prepareLocationRequest(mTask.getOptions());
185
185
  mPendingIntent = preparePendingIntent();
186
186
 
187
187
  try {
@@ -1,8 +1,13 @@
1
1
  import { PermissionStatus, PermissionResponse, PermissionHookOptions } from 'expo-modules-core';
2
2
  import { LocationAccuracy, LocationCallback, LocationGeocodedAddress, LocationGeocodedLocation, LocationHeadingCallback, LocationHeadingObject, LocationLastKnownOptions, LocationObject, LocationOptions, LocationPermissionResponse, LocationProviderStatus, LocationRegion, LocationSubscription, LocationTaskOptions, LocationActivityType, LocationGeofencingEventType, LocationGeofencingRegionState, LocationGeocodingOptions } from './Location.types';
3
3
  import { LocationEventEmitter } from './LocationEventEmitter';
4
- import { setGoogleApiKey } from './LocationGoogleGeocoding';
5
4
  import { _getCurrentWatchId } from './LocationSubscribers';
5
+ /**
6
+ * @deprecated The Geocoding web api is no longer available from SDK 49 onwards. Use [Place Autocomplete](https://developers.google.com/maps/documentation/places/web-service/autocomplete) instead.
7
+ * @param apiKey Google API key obtained from Google API Console. This API key must have `Geocoding API`
8
+ * enabled, otherwise your geocoding requests will be denied.
9
+ */
10
+ declare function setGoogleApiKey(_apiKey: string): void;
6
11
  /**
7
12
  * Check status of location providers.
8
13
  * @return A promise which fulfills with an object of type [LocationProviderStatus](#locationproviderstatus).
@@ -61,6 +66,8 @@ export declare function getHeadingAsync(): Promise<LocationHeadingObject>;
61
66
  export declare function watchHeadingAsync(callback: LocationHeadingCallback): Promise<LocationSubscription>;
62
67
  /**
63
68
  * Geocode an address string to latitude-longitude location.
69
+ * > **Note**: Using the Geocoding web api is no longer supported. Use [Place Autocomplete](https://developers.google.com/maps/documentation/places/web-service/autocomplete) instead.
70
+ *
64
71
  * > **Note**: Geocoding is resource consuming and has to be used reasonably. Creating too many
65
72
  * > requests at a time can result in an error, so they have to be managed properly.
66
73
  * > It's also discouraged to use geocoding while the app is in the background and its results won't
@@ -75,6 +82,8 @@ export declare function watchHeadingAsync(callback: LocationHeadingCallback): Pr
75
82
  export declare function geocodeAsync(address: string, options?: LocationGeocodingOptions): Promise<LocationGeocodedLocation[]>;
76
83
  /**
77
84
  * Reverse geocode a location to postal address.
85
+ * > **Note**: Using the Geocoding web api is no longer supported. Use [Place Autocomplete](https://developers.google.com/maps/documentation/places/web-service/autocomplete) instead.
86
+ *
78
87
  * > **Note**: Geocoding is resource consuming and has to be used reasonably. Creating too many
79
88
  * > requests at a time can result in an error, so they have to be managed properly.
80
89
  * > It's also discouraged to use geocoding while the app is in the background and its results won't
@@ -1 +1 @@
1
- {"version":3,"file":"Location.d.ts","sourceRoot":"","sources":["../src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AAE,MAAM,EAChB,OAAO,GAAE,cAAc,EAAO,GAC7B,OAAO,CAAC,IAAI,CAAC,CAIf;AAGD;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGzE;AAGD;;;;GAIG;AACH,wBAAsB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAGlF;AAED,OAAO,EAAE,oBAAoB,IAAI,YAAY,EAAE,kBAAkB,EAAE,CAAC;AAEpE,OAAO,EACL,gBAAgB,IAAI,QAAQ,EAC5B,oBAAoB,IAAI,YAAY,EACpC,2BAA2B,IAAI,mBAAmB,EAClD,6BAA6B,IAAI,qBAAqB,EACtD,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,GAChB,CAAC;AAEF,OAAO,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AACtE,cAAc,kBAAkB,CAAC"}
package/build/Location.js CHANGED
@@ -2,9 +2,15 @@ import { PermissionStatus, createPermissionHook, Platform, } from 'expo-modules-
2
2
  import ExpoLocation from './ExpoLocation';
3
3
  import { LocationAccuracy, LocationActivityType, LocationGeofencingEventType, LocationGeofencingRegionState, } from './Location.types';
4
4
  import { LocationEventEmitter } from './LocationEventEmitter';
5
- import { setGoogleApiKey, googleGeocodeAsync, googleReverseGeocodeAsync, } from './LocationGoogleGeocoding';
6
5
  import { LocationSubscriber, HeadingSubscriber, _getCurrentWatchId } from './LocationSubscribers';
7
6
  // @needsAudit
7
+ /**
8
+ * @deprecated The Geocoding web api is no longer available from SDK 49 onwards. Use [Place Autocomplete](https://developers.google.com/maps/documentation/places/web-service/autocomplete) instead.
9
+ * @param apiKey Google API key obtained from Google API Console. This API key must have `Geocoding API`
10
+ * enabled, otherwise your geocoding requests will be denied.
11
+ */
12
+ function setGoogleApiKey(_apiKey) { }
13
+ // @needsAudit
8
14
  /**
9
15
  * Check status of location providers.
10
16
  * @return A promise which fulfills with an object of type [LocationProviderStatus](#locationproviderstatus).
@@ -113,6 +119,8 @@ export async function watchHeadingAsync(callback) {
113
119
  // @needsAudit
114
120
  /**
115
121
  * Geocode an address string to latitude-longitude location.
122
+ * > **Note**: Using the Geocoding web api is no longer supported. Use [Place Autocomplete](https://developers.google.com/maps/documentation/places/web-service/autocomplete) instead.
123
+ *
116
124
  * > **Note**: Geocoding is resource consuming and has to be used reasonably. Creating too many
117
125
  * > requests at a time can result in an error, so they have to be managed properly.
118
126
  * > It's also discouraged to use geocoding while the app is in the background and its results won't
@@ -129,13 +137,19 @@ export async function geocodeAsync(address, options) {
129
137
  throw new TypeError(`Address to geocode must be a string. Got ${address} instead.`);
130
138
  }
131
139
  if (options?.useGoogleMaps || Platform.OS === 'web') {
132
- return await googleGeocodeAsync(address);
140
+ if (__DEV__) {
141
+ console.warn('The Geocoding API has been removed in SDK 49, use Place Autocomplete service instead' +
142
+ '(https://developers.google.com/maps/documentation/places/web-service/autocomplete)');
143
+ }
144
+ return [];
133
145
  }
134
146
  return await ExpoLocation.geocodeAsync(address);
135
147
  }
136
148
  // @needsAudit
137
149
  /**
138
150
  * Reverse geocode a location to postal address.
151
+ * > **Note**: Using the Geocoding web api is no longer supported. Use [Place Autocomplete](https://developers.google.com/maps/documentation/places/web-service/autocomplete) instead.
152
+ *
139
153
  * > **Note**: Geocoding is resource consuming and has to be used reasonably. Creating too many
140
154
  * > requests at a time can result in an error, so they have to be managed properly.
141
155
  * > It's also discouraged to use geocoding while the app is in the background and its results won't
@@ -152,7 +166,11 @@ export async function reverseGeocodeAsync(location, options) {
152
166
  throw new TypeError('Location to reverse-geocode must be an object with number properties `latitude` and `longitude`.');
153
167
  }
154
168
  if (options?.useGoogleMaps || Platform.OS === 'web') {
155
- return await googleReverseGeocodeAsync(location);
169
+ if (__DEV__) {
170
+ console.warn('The Geocoding API has been removed in SDK 49, use Place Autocomplete service instead' +
171
+ '(https://developers.google.com/maps/documentation/places/web-service/autocomplete)');
172
+ }
173
+ return [];
156
174
  }
157
175
  return await ExpoLocation.reverseGeocodeAsync(location);
158
176
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Location.js","sourceRoot":"","sources":["../src/Location.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAGhB,oBAAoB,EACpB,QAAQ,GACT,MAAM,mBAAmB,CAAC;AAE3B,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EACL,gBAAgB,EAchB,oBAAoB,EACpB,2BAA2B,EAC3B,6BAA6B,GAE9B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAElG,cAAc;AACd;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB;IAC1C,OAAO,YAAY,CAAC,sBAAsB,EAAE,CAAC;AAC/C,CAAC;AAED,cAAc;AACd;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B;IAC9C,kFAAkF;IAClF,qGAAqG;IACrG,+GAA+G;IAC/G,wFAAwF;IAExF,IAAI,QAAQ,CAAC,EAAE,KAAK,SAAS,EAAE;QAC7B,OAAO,YAAY,CAAC,0BAA0B,EAAE,CAAC;KAClD;AACH,CAAC;AAED,cAAc;AACd;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,UAA2B,EAAE;IAE7B,OAAO,YAAY,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC;AACvD,CAAC;AAED,cAAc;AACd;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,UAAoC,EAAE;IAEtC,OAAO,YAAY,CAAC,yBAAyB,CAAC,OAAO,CAAC,CAAC;A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C,MAAM,YAAY,CAAC,CAAC;SAC1F;KACF;AACH,CAAC;AAED,cAAc;AACd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,QAAgB,EAChB,UAA4B,EAAE;IAE9B,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAC5B,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAC1B,MAAM,YAAY,CAAC,oBAAoB,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;AACjE,CAAC;AAED,cAAc;AACd;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,QAAgB;IACxD,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAC5B,MAAM,YAAY,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;AACnD,CAAC;AAED,cAAc;AACd;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAAC,QAAgB;IAC9D,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAC5B,OAAO,YAAY,CAAC,yBAAyB,CAAC,QAAQ,CAAC,CAAC;AAC1D,CAAC;AAED,OAAO,EAAE,oBAAoB,IAAI,YAAY,EAAE,kBAAkB,EAAE,CAAC;AAEpE,OAAO,EACL,gBAAgB,IAAI,QAAQ,EAC5B,oBAAoB,IAAI,YAAY,EACpC,2BAA2B,IAAI,mBAAmB,EAClD,6BAA6B,IAAI,qBAAqB,EACtD,gBAAgB,EAEhB,eAAe,GAChB,CAAC;AAEF,OAAO,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AACtE,cAAc,kBAAkB,CAAC","sourcesContent":["import {\n PermissionStatus,\n PermissionResponse,\n PermissionHookOptions,\n createPermissionHook,\n Platform,\n} from 'expo-modules-core';\n\nimport ExpoLocation from './ExpoLocation';\nimport {\n LocationAccuracy,\n LocationCallback,\n LocationGeocodedAddress,\n LocationGeocodedLocation,\n LocationHeadingCallback,\n LocationHeadingObject,\n LocationLastKnownOptions,\n LocationObject,\n LocationOptions,\n LocationPermissionResponse,\n LocationProviderStatus,\n LocationRegion,\n LocationSubscription,\n LocationTaskOptions,\n LocationActivityType,\n LocationGeofencingEventType,\n LocationGeofencingRegionState,\n LocationGeocodingOptions,\n} from './Location.types';\nimport { LocationEventEmitter } from './LocationEventEmitter';\nimport {\n setGoogleApiKey,\n googleGeocodeAsync,\n googleReverseGeocodeAsync,\n} from './LocationGoogleGeocoding';\nimport { LocationSubscriber, HeadingSubscriber, _getCurrentWatchId } from './LocationSubscribers';\n\n// @needsAudit\n/**\n * Check status of location providers.\n * @return A promise which fulfills with an object of type [LocationProviderStatus](#locationproviderstatus).\n */\nexport async function getProviderStatusAsync(): Promise<LocationProviderStatus> {\n return ExpoLocation.getProviderStatusAsync();\n}\n\n// @needsAudit\n/**\n * Asks the user to turn on high accuracy location mode which enables network provider that uses\n * Google Play services to improve location accuracy and location-based services.\n * @return A promise resolving as soon as the user accepts the dialog. Rejects if denied.\n */\nexport async function enableNetworkProviderAsync(): Promise<void> {\n // If network provider is disabled (user's location mode is set to \"Device only\"),\n // Android's location provider may not give you any results. Use this method in order to ask the user\n // to change the location mode to \"High accuracy\" which uses Google Play services and enables network provider.\n // `getCurrentPositionAsync` and `watchPositionAsync` are doing it automatically anyway.\n\n if (Platform.OS === 'android') {\n return ExpoLocation.enableNetworkProviderAsync();\n }\n}\n\n// @needsAudit\n/**\n * Requests for one-time delivery of the user's current location.\n * Depending on given `accuracy` option it may take some time to resolve,\n * especially when you're inside a building.\n * > __Note:__ Calling it causes the location manager to obtain a location fix which may take several\n * > seconds. Consider using [`Location.getLastKnownPositionAsync`](#locationgetlastknownpositionasyncoptions)\n * > if you expect to get a quick response and high accuracy is not required.\n * @param options\n * @return A promise which fulfills with an object of type [`LocationObject`](#locationobject).\n */\nexport async function getCurrentPositionAsync(\n options: LocationOptions = {}\n): Promise<LocationObject> {\n return ExpoLocation.getCurrentPositionAsync(options);\n}\n\n// @needsAudit\n/**\n * Gets the last known position of the device or `null` if it's not available or doesn't match given\n * requirements such as maximum age or required accuracy.\n * It's considered to be faster than `getCurrentPositionAsync` as it doesn't request for the current\n * location, but keep in mind the returned location may not be up-to-date.\n * @param options\n * @return A promise which fulfills with an object of type [LocationObject](#locationobject) or\n * `null` if it's not available or doesn't match given requirements such as maximum age or required\n * accuracy.\n */\nexport async function getLastKnownPositionAsync(\n options: LocationLastKnownOptions = {}\n): Promise<LocationObject | null> {\n return ExpoLocation.getLastKnownPositionAsync(options);\n}\n\n// @needsAudit\n/**\n * Subscribe to location updates from the device. Please note that updates will only occur while the\n * application is in the foreground. To get location updates while in background you'll need to use\n * [Location.startLocationUpdatesAsync](#locationstartlocationupdatesasynctaskname-options).\n * @param options\n * @param callback This function is called on each location update. It receives an object of type\n * [`LocationObject`](#locationobject) as the first argument.\n * @return A promise which fulfills with a [`LocationSubscription`](#locationsubscription) object.\n */\nexport async function watchPositionAsync(\n options: LocationOptions,\n callback: LocationCallback\n): Promise<LocationSubscription> {\n const watchId = LocationSubscriber.registerCallback(callback);\n await ExpoLocation.watchPositionImplAsync(watchId, options);\n\n return {\n remove() {\n LocationSubscriber.unregisterCallback(watchId);\n },\n };\n}\n\n// @needsAudit\n/**\n * Gets the current heading information from the device. To simplify, it calls `watchHeadingAsync`\n * and waits for a couple of updates, and then returns the one that is accurate enough.\n * @return A promise which fulfills with an object of type [LocationHeadingObject](#locationheadingobject).\n */\nexport async function getHeadingAsync(): Promise<LocationHeadingObject> {\n return new Promise(async (resolve) => {\n let tries = 0;\n\n const subscription = await watchHeadingAsync((heading) => {\n if (heading.accuracy > 1 || tries > 5) {\n subscription.remove();\n resolve(heading);\n } else {\n tries += 1;\n }\n });\n });\n}\n\n// @needsAudit\n/**\n * Subscribe to compass updates from the device.\n * @param callback This function is called on each compass update. It receives an object of type\n * [LocationHeadingObject](#locationheadingobject) as the first argument.\n * @return A promise which fulfills with a [`LocationSubscription`](#locationsubscription) object.\n */\nexport async function watchHeadingAsync(\n callback: LocationHeadingCallback\n): Promise<LocationSubscription> {\n const watchId = HeadingSubscriber.registerCallback(callback);\n await ExpoLocation.watchDeviceHeading(watchId);\n\n return {\n remove() {\n HeadingSubscriber.unregisterCallback(watchId);\n },\n };\n}\n\n// @needsAudit\n/**\n * Geocode an address string to latitude-longitude location.\n * > **Note**: Geocoding is resource consuming and has to be used reasonably. Creating too many\n * > requests at a time can result in an error, so they have to be managed properly.\n * > It's also discouraged to use geocoding while the app is in the background and its results won't\n * > be shown to the user immediately.\n *\n * > On Android, you must request a location permission (`Permissions.LOCATION`) from the user\n * > before geocoding can be used.\n * @param address A string representing address, eg. `\"Baker Street London\"`.\n * @param options\n * @return A promise which fulfills with an array (in most cases its size is 1) of [`LocationGeocodedLocation`](#locationgeocodedlocation) objects.\n */\nexport async function geocodeAsync(\n address: string,\n options?: LocationGeocodingOptions\n): Promise<LocationGeocodedLocation[]> {\n if (typeof address !== 'string') {\n throw new TypeError(`Address to geocode must be a string. Got ${address} instead.`);\n }\n if (options?.useGoogleMaps || Platform.OS === 'web') {\n return await googleGeocodeAsync(address);\n }\n return await ExpoLocation.geocodeAsync(address);\n}\n\n// @needsAudit\n/**\n * Reverse geocode a location to postal address.\n * > **Note**: Geocoding is resource consuming and has to be used reasonably. Creating too many\n * > requests at a time can result in an error, so they have to be managed properly.\n * > It's also discouraged to use geocoding while the app is in the background and its results won't\n * > be shown to the user immediately.\n *\n * > On Android, you must request a location permission (`Permissions.LOCATION`) from the user\n * > before geocoding can be used.\n * @param location An object representing a location.\n * @param options\n * @return A promise which fulfills with an array (in most cases its size is 1) of [`LocationGeocodedAddress`](#locationgeocodedaddress) objects.\n */\nexport async function reverseGeocodeAsync(\n location: Pick<LocationGeocodedLocation, 'latitude' | 'longitude'>,\n options?: LocationGeocodingOptions\n): Promise<LocationGeocodedAddress[]> {\n if (typeof location.latitude !== 'number' || typeof location.longitude !== 'number') {\n throw new TypeError(\n 'Location to reverse-geocode must be an object with number properties `latitude` and `longitude`.'\n );\n }\n if (options?.useGoogleMaps || Platform.OS === 'web') {\n return await googleReverseGeocodeAsync(location);\n }\n return await ExpoLocation.reverseGeocodeAsync(location);\n}\n\n// @needsAudit\n/**\n * Checks user's permissions for accessing location.\n * @return A promise that fulfills with an object of type [LocationPermissionResponse](#locationpermissionresponse).\n * @deprecated Use [`getForegroundPermissionsAsync`](#locationgetforegroundpermissionsasync) or [`getBackgroundPermissionsAsync`](#locationgetbackgroundpermissionsasync) instead.\n */\nexport async function getPermissionsAsync(): Promise<LocationPermissionResponse> {\n console.warn(\n `\"getPermissionsAsync()\" is now deprecated. Please use \"getForegroundPermissionsAsync()\" or \"getBackgroundPermissionsAsync()\" instead.`\n );\n return await ExpoLocation.getPermissionsAsync();\n}\n\n// @needsAudit\n/**\n * Asks the user to grant permissions for location.\n * @return A promise that fulfills with an object of type [LocationPermissionResponse](#locationpermissionresponse).\n * @deprecated Use [`requestForegroundPermissionsAsync`](#locationrequestforegroundpermissionsasync) or [`requestBackgroundPermissionsAsync`](#locationrequestbackgroundpermissionsasync) instead.\n */\nexport async function requestPermissionsAsync(): Promise<LocationPermissionResponse> {\n console.warn(\n `\"requestPermissionsAsync()\" is now deprecated. Please use \"requestForegroundPermissionsAsync()\" or \"requestBackgroundPermissionsAsync()\" instead.`\n );\n\n return await ExpoLocation.requestPermissionsAsync();\n}\n\n// @needsAudit\n/**\n * Checks user's permissions for accessing location while the app is in the foreground.\n * @return A promise that fulfills with an object of type [PermissionResponse](#permissionresponse).\n */\nexport async function getForegroundPermissionsAsync(): Promise<LocationPermissionResponse> {\n return await ExpoLocation.getForegroundPermissionsAsync();\n}\n\n// @needsAudit\n/**\n * Asks the user to grant permissions for location while the app is in the foreground.\n * @return A promise that fulfills with an object of type [PermissionResponse](#permissionresponse).\n */\nexport async function requestForegroundPermissionsAsync(): Promise<LocationPermissionResponse> {\n return await ExpoLocation.requestForegroundPermissionsAsync();\n}\n\n// @needsAudit\n/**\n * Check or request permissions for the foreground location.\n * This uses both `requestForegroundPermissionsAsync` and `getForegroundPermissionsAsync` to interact with the permissions.\n *\n * @example\n * ```ts\n * const [status, requestPermission] = Location.useForegroundPermissions();\n * ```\n */\nexport const useForegroundPermissions = createPermissionHook({\n getMethod: getForegroundPermissionsAsync,\n requestMethod: requestForegroundPermissionsAsync,\n});\n\n// @needsAudit\n/**\n * Checks user's permissions for accessing location while the app is in the background.\n * @return A promise that fulfills with an object of type [PermissionResponse](#permissionresponse).\n */\nexport async function getBackgroundPermissionsAsync(): Promise<PermissionResponse> {\n return await ExpoLocation.getBackgroundPermissionsAsync();\n}\n\n// @needsAudit\n/**\n * Asks the user to grant permissions for location while the app is in the background.\n * On __Android 11 or higher__: this method will open the system settings page - before that happens\n * you should explain to the user why your application needs background location permission.\n * For example, you can use `Modal` component from `react-native` to do that.\n * > __Note__: Foreground permissions should be granted before asking for the background permissions\n * (your app can't obtain background permission without foreground permission).\n * @return A promise that fulfills with an object of type [PermissionResponse](#permissionresponse).\n */\nexport async function requestBackgroundPermissionsAsync(): Promise<PermissionResponse> {\n return await ExpoLocation.requestBackgroundPermissionsAsync();\n}\n\n// @needsAudit\n/**\n * Check or request permissions for the background location.\n * This uses both `requestBackgroundPermissionsAsync` and `getBackgroundPermissionsAsync` to\n * interact with the permissions.\n *\n * @example\n * ```ts\n * const [status, requestPermission] = Location.useBackgroundPermissions();\n * ```\n */\nexport const useBackgroundPermissions = createPermissionHook({\n getMethod: getBackgroundPermissionsAsync,\n requestMethod: requestBackgroundPermissionsAsync,\n});\n\n// --- Location service\n\n// @needsAudit\n/**\n * Checks whether location services are enabled by the user.\n * @return A promise which fulfills to `true` if location services are enabled on the device,\n * or `false` if not.\n */\nexport async function hasServicesEnabledAsync(): Promise<boolean> {\n return await ExpoLocation.hasServicesEnabledAsync();\n}\n\n// --- Background location updates\n\nfunction _validateTaskName(taskName: string) {\n if (!taskName || typeof taskName !== 'string') {\n throw new Error(`\\`taskName\\` must be a non-empty string. Got ${taskName} instead.`);\n }\n}\n\n// @docsMissing\nexport async function isBackgroundLocationAvailableAsync(): Promise<boolean> {\n const providerStatus = await getProviderStatusAsync();\n return providerStatus.backgroundModeEnabled;\n}\n\n// @needsAudit\n/**\n * Registers for receiving location updates that can also come when the app is in the background.\n *\n * # Task parameters\n *\n * Background location task will be receiving following data:\n * - `locations` - An array of the new locations.\n *\n * ```ts\n * import * as TaskManager from 'expo-task-manager';\n *\n * TaskManager.defineTask(YOUR_TASK_NAME, ({ data: { locations }, error }) => {\n * if (error) {\n * // check `error.message` for more details.\n * return;\n * }\n * console.log('Received new locations', locations);\n * });\n * ```\n *\n * @param taskName Name of the task receiving location updates.\n * @param options An object of options passed to the location manager.\n *\n * @return A promise resolving once the task with location updates is registered.\n */\nexport async function startLocationUpdatesAsync(\n taskName: string,\n options: LocationTaskOptions = { accuracy: LocationAccuracy.Balanced }\n): Promise<void> {\n _validateTaskName(taskName);\n await ExpoLocation.startLocationUpdatesAsync(taskName, options);\n}\n\n// @needsAudit\n/**\n * Stops geofencing for specified task.\n * @param taskName Name of the background location task to stop.\n * @return A promise resolving as soon as the task is unregistered.\n */\nexport async function stopLocationUpdatesAsync(taskName: string): Promise<void> {\n _validateTaskName(taskName);\n await ExpoLocation.stopLocationUpdatesAsync(taskName);\n}\n\n// @needsAudit\n/**\n * @param taskName Name of the location task to check.\n * @return A promise which fulfills with boolean value indicating whether the location task is\n * started or not.\n */\nexport async function hasStartedLocationUpdatesAsync(taskName: string): Promise<boolean> {\n _validateTaskName(taskName);\n return ExpoLocation.hasStartedLocationUpdatesAsync(taskName);\n}\n\n// --- Geofencing\n\nfunction _validateRegions(regions: LocationRegion[]) {\n if (!regions || regions.length === 0) {\n throw new Error(\n 'Regions array cannot be empty. Use `stopGeofencingAsync` if you want to stop geofencing all regions'\n );\n }\n for (const region of regions) {\n if (typeof region.latitude !== 'number') {\n throw new TypeError(`Region's latitude must be a number. Got '${region.latitude}' instead.`);\n }\n if (typeof region.longitude !== 'number') {\n throw new TypeError(\n `Region's longitude must be a number. Got '${region.longitude}' instead.`\n );\n }\n if (typeof region.radius !== 'number') {\n throw new TypeError(`Region's radius must be a number. Got '${region.radius}' instead.`);\n }\n }\n}\n\n// @needsAudit\n/**\n * Starts geofencing for given regions. When the new event comes, the task with specified name will\n * be called with the region that the device enter to or exit from.\n * If you want to add or remove regions from already running geofencing task, you can just call\n * `startGeofencingAsync` again with the new array of regions.\n *\n * # Task parameters\n *\n * Geofencing task will be receiving following data:\n * - `eventType` - Indicates the reason for calling the task, which can be triggered by entering or exiting the region.\n * See [GeofencingEventType](#geofencingeventtype).\n * - `region` - Object containing details about updated region. See [LocationRegion](#locationregion) for more details.\n *\n * @param taskName Name of the task that will be called when the device enters or exits from specified regions.\n * @param regions Array of region objects to be geofenced.\n *\n * @return A promise resolving as soon as the task is registered.\n *\n * @example\n * ```ts\n * import { GeofencingEventType } from 'expo-location';\n * import * as TaskManager from 'expo-task-manager';\n *\n * TaskManager.defineTask(YOUR_TASK_NAME, ({ data: { eventType, region }, error }) => {\n * if (error) {\n * // check `error.message` for more details.\n * return;\n * }\n * if (eventType === GeofencingEventType.Enter) {\n * console.log(\"You've entered region:\", region);\n * } else if (eventType === GeofencingEventType.Exit) {\n * console.log(\"You've left region:\", region);\n * }\n * });\n * ```\n */\nexport async function startGeofencingAsync(\n taskName: string,\n regions: LocationRegion[] = []\n): Promise<void> {\n _validateTaskName(taskName);\n _validateRegions(regions);\n await ExpoLocation.startGeofencingAsync(taskName, { regions });\n}\n\n// @needsAudit\n/**\n * Stops geofencing for specified task. It unregisters the background task so the app will not be\n * receiving any updates, especially in the background.\n * @param taskName Name of the task to unregister.\n * @return A promise resolving as soon as the task is unregistered.\n */\nexport async function stopGeofencingAsync(taskName: string): Promise<void> {\n _validateTaskName(taskName);\n await ExpoLocation.stopGeofencingAsync(taskName);\n}\n\n// @needsAudit\n/**\n * @param taskName Name of the geofencing task to check.\n * @return A promise which fulfills with boolean value indicating whether the geofencing task is\n * started or not.\n */\nexport async function hasStartedGeofencingAsync(taskName: string): Promise<boolean> {\n _validateTaskName(taskName);\n return ExpoLocation.hasStartedGeofencingAsync(taskName);\n}\n\nexport { LocationEventEmitter as EventEmitter, _getCurrentWatchId };\n\nexport {\n LocationAccuracy as Accuracy,\n LocationActivityType as ActivityType,\n LocationGeofencingEventType as GeofencingEventType,\n LocationGeofencingRegionState as GeofencingRegionState,\n PermissionStatus,\n PermissionHookOptions,\n setGoogleApiKey,\n};\n\nexport { installWebGeolocationPolyfill } from './GeolocationPolyfill';\nexport * from './Location.types';\n"]}
1
+ {"version":3,"file":"Location.js","sourceRoot":"","sources":["../src/Location.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAGhB,oBAAoB,EACpB,QAAQ,GACT,MAAM,mBAAmB,CAAC;AAE3B,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EACL,gBAAgB,EAchB,oBAAoB,EACpB,2BAA2B,EAC3B,6BAA6B,GAE9B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAElG,cAAc;AACd;;;;GAIG;AACH,SAAS,eAAe,CAAC,OAAe,IAAG,CAAC;AAE5C,cAAc;AACd;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB;IAC1C,OAAO,YAAY,CAAC,sBAAsB,EAAE,CAAC;AAC/C,CAAC;AAED,cAAc;AACd;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B;IAC9C,kFAAkF;IAClF,qGAAqG;IACrG,+GAA+G;IAC/G,wFAAwF;IAExF,IAAI,QAAQ,CAAC,EAAE,KAAK,SAAS,EAAE;QAC7B,OAAO,YAAY,CAAC,0BAA0B,EAAE,CAAC;KAClD;AACH,CAAC;AAED,cAAc;AACd;;;;;;;;;GASG;AACH,MA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Q,EAC5B,oBAAoB,IAAI,YAAY,EACpC,2BAA2B,IAAI,mBAAmB,EAClD,6BAA6B,IAAI,qBAAqB,EACtD,gBAAgB,EAEhB,eAAe,GAChB,CAAC;AAEF,OAAO,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AACtE,cAAc,kBAAkB,CAAC","sourcesContent":["import {\n PermissionStatus,\n PermissionResponse,\n PermissionHookOptions,\n createPermissionHook,\n Platform,\n} from 'expo-modules-core';\n\nimport ExpoLocation from './ExpoLocation';\nimport {\n LocationAccuracy,\n LocationCallback,\n LocationGeocodedAddress,\n LocationGeocodedLocation,\n LocationHeadingCallback,\n LocationHeadingObject,\n LocationLastKnownOptions,\n LocationObject,\n LocationOptions,\n LocationPermissionResponse,\n LocationProviderStatus,\n LocationRegion,\n LocationSubscription,\n LocationTaskOptions,\n LocationActivityType,\n LocationGeofencingEventType,\n LocationGeofencingRegionState,\n LocationGeocodingOptions,\n} from './Location.types';\nimport { LocationEventEmitter } from './LocationEventEmitter';\nimport { LocationSubscriber, HeadingSubscriber, _getCurrentWatchId } from './LocationSubscribers';\n\n// @needsAudit\n/**\n * @deprecated The Geocoding web api is no longer available from SDK 49 onwards. Use [Place Autocomplete](https://developers.google.com/maps/documentation/places/web-service/autocomplete) instead.\n * @param apiKey Google API key obtained from Google API Console. This API key must have `Geocoding API`\n * enabled, otherwise your geocoding requests will be denied.\n */\nfunction setGoogleApiKey(_apiKey: string) {}\n\n// @needsAudit\n/**\n * Check status of location providers.\n * @return A promise which fulfills with an object of type [LocationProviderStatus](#locationproviderstatus).\n */\nexport async function getProviderStatusAsync(): Promise<LocationProviderStatus> {\n return ExpoLocation.getProviderStatusAsync();\n}\n\n// @needsAudit\n/**\n * Asks the user to turn on high accuracy location mode which enables network provider that uses\n * Google Play services to improve location accuracy and location-based services.\n * @return A promise resolving as soon as the user accepts the dialog. Rejects if denied.\n */\nexport async function enableNetworkProviderAsync(): Promise<void> {\n // If network provider is disabled (user's location mode is set to \"Device only\"),\n // Android's location provider may not give you any results. Use this method in order to ask the user\n // to change the location mode to \"High accuracy\" which uses Google Play services and enables network provider.\n // `getCurrentPositionAsync` and `watchPositionAsync` are doing it automatically anyway.\n\n if (Platform.OS === 'android') {\n return ExpoLocation.enableNetworkProviderAsync();\n }\n}\n\n// @needsAudit\n/**\n * Requests for one-time delivery of the user's current location.\n * Depending on given `accuracy` option it may take some time to resolve,\n * especially when you're inside a building.\n * > __Note:__ Calling it causes the location manager to obtain a location fix which may take several\n * > seconds. Consider using [`Location.getLastKnownPositionAsync`](#locationgetlastknownpositionasyncoptions)\n * > if you expect to get a quick response and high accuracy is not required.\n * @param options\n * @return A promise which fulfills with an object of type [`LocationObject`](#locationobject).\n */\nexport async function getCurrentPositionAsync(\n options: LocationOptions = {}\n): Promise<LocationObject> {\n return ExpoLocation.getCurrentPositionAsync(options);\n}\n\n// @needsAudit\n/**\n * Gets the last known position of the device or `null` if it's not available or doesn't match given\n * requirements such as maximum age or required accuracy.\n * It's considered to be faster than `getCurrentPositionAsync` as it doesn't request for the current\n * location, but keep in mind the returned location may not be up-to-date.\n * @param options\n * @return A promise which fulfills with an object of type [LocationObject](#locationobject) or\n * `null` if it's not available or doesn't match given requirements such as maximum age or required\n * accuracy.\n */\nexport async function getLastKnownPositionAsync(\n options: LocationLastKnownOptions = {}\n): Promise<LocationObject | null> {\n return ExpoLocation.getLastKnownPositionAsync(options);\n}\n\n// @needsAudit\n/**\n * Subscribe to location updates from the device. Please note that updates will only occur while the\n * application is in the foreground. To get location updates while in background you'll need to use\n * [Location.startLocationUpdatesAsync](#locationstartlocationupdatesasynctaskname-options).\n * @param options\n * @param callback This function is called on each location update. It receives an object of type\n * [`LocationObject`](#locationobject) as the first argument.\n * @return A promise which fulfills with a [`LocationSubscription`](#locationsubscription) object.\n */\nexport async function watchPositionAsync(\n options: LocationOptions,\n callback: LocationCallback\n): Promise<LocationSubscription> {\n const watchId = LocationSubscriber.registerCallback(callback);\n await ExpoLocation.watchPositionImplAsync(watchId, options);\n\n return {\n remove() {\n LocationSubscriber.unregisterCallback(watchId);\n },\n };\n}\n\n// @needsAudit\n/**\n * Gets the current heading information from the device. To simplify, it calls `watchHeadingAsync`\n * and waits for a couple of updates, and then returns the one that is accurate enough.\n * @return A promise which fulfills with an object of type [LocationHeadingObject](#locationheadingobject).\n */\nexport async function getHeadingAsync(): Promise<LocationHeadingObject> {\n return new Promise(async (resolve) => {\n let tries = 0;\n\n const subscription = await watchHeadingAsync((heading) => {\n if (heading.accuracy > 1 || tries > 5) {\n subscription.remove();\n resolve(heading);\n } else {\n tries += 1;\n }\n });\n });\n}\n\n// @needsAudit\n/**\n * Subscribe to compass updates from the device.\n * @param callback This function is called on each compass update. It receives an object of type\n * [LocationHeadingObject](#locationheadingobject) as the first argument.\n * @return A promise which fulfills with a [`LocationSubscription`](#locationsubscription) object.\n */\nexport async function watchHeadingAsync(\n callback: LocationHeadingCallback\n): Promise<LocationSubscription> {\n const watchId = HeadingSubscriber.registerCallback(callback);\n await ExpoLocation.watchDeviceHeading(watchId);\n\n return {\n remove() {\n HeadingSubscriber.unregisterCallback(watchId);\n },\n };\n}\n\n// @needsAudit\n/**\n * Geocode an address string to latitude-longitude location.\n * > **Note**: Using the Geocoding web api is no longer supported. Use [Place Autocomplete](https://developers.google.com/maps/documentation/places/web-service/autocomplete) instead.\n *\n * > **Note**: Geocoding is resource consuming and has to be used reasonably. Creating too many\n * > requests at a time can result in an error, so they have to be managed properly.\n * > It's also discouraged to use geocoding while the app is in the background and its results won't\n * > be shown to the user immediately.\n *\n * > On Android, you must request a location permission (`Permissions.LOCATION`) from the user\n * > before geocoding can be used.\n * @param address A string representing address, eg. `\"Baker Street London\"`.\n * @param options\n * @return A promise which fulfills with an array (in most cases its size is 1) of [`LocationGeocodedLocation`](#locationgeocodedlocation) objects.\n */\nexport async function geocodeAsync(\n address: string,\n options?: LocationGeocodingOptions\n): Promise<LocationGeocodedLocation[]> {\n if (typeof address !== 'string') {\n throw new TypeError(`Address to geocode must be a string. Got ${address} instead.`);\n }\n\n if (options?.useGoogleMaps || Platform.OS === 'web') {\n if (__DEV__) {\n console.warn(\n 'The Geocoding API has been removed in SDK 49, use Place Autocomplete service instead' +\n '(https://developers.google.com/maps/documentation/places/web-service/autocomplete)'\n );\n }\n return [];\n }\n\n return await ExpoLocation.geocodeAsync(address);\n}\n\n// @needsAudit\n/**\n * Reverse geocode a location to postal address.\n * > **Note**: Using the Geocoding web api is no longer supported. Use [Place Autocomplete](https://developers.google.com/maps/documentation/places/web-service/autocomplete) instead.\n *\n * > **Note**: Geocoding is resource consuming and has to be used reasonably. Creating too many\n * > requests at a time can result in an error, so they have to be managed properly.\n * > It's also discouraged to use geocoding while the app is in the background and its results won't\n * > be shown to the user immediately.\n *\n * > On Android, you must request a location permission (`Permissions.LOCATION`) from the user\n * > before geocoding can be used.\n * @param location An object representing a location.\n * @param options\n * @return A promise which fulfills with an array (in most cases its size is 1) of [`LocationGeocodedAddress`](#locationgeocodedaddress) objects.\n */\nexport async function reverseGeocodeAsync(\n location: Pick<LocationGeocodedLocation, 'latitude' | 'longitude'>,\n options?: LocationGeocodingOptions\n): Promise<LocationGeocodedAddress[]> {\n if (typeof location.latitude !== 'number' || typeof location.longitude !== 'number') {\n throw new TypeError(\n 'Location to reverse-geocode must be an object with number properties `latitude` and `longitude`.'\n );\n }\n\n if (options?.useGoogleMaps || Platform.OS === 'web') {\n if (__DEV__) {\n console.warn(\n 'The Geocoding API has been removed in SDK 49, use Place Autocomplete service instead' +\n '(https://developers.google.com/maps/documentation/places/web-service/autocomplete)'\n );\n }\n return [];\n }\n\n return await ExpoLocation.reverseGeocodeAsync(location);\n}\n\n// @needsAudit\n/**\n * Checks user's permissions for accessing location.\n * @return A promise that fulfills with an object of type [LocationPermissionResponse](#locationpermissionresponse).\n * @deprecated Use [`getForegroundPermissionsAsync`](#locationgetforegroundpermissionsasync) or [`getBackgroundPermissionsAsync`](#locationgetbackgroundpermissionsasync) instead.\n */\nexport async function getPermissionsAsync(): Promise<LocationPermissionResponse> {\n console.warn(\n `\"getPermissionsAsync()\" is now deprecated. Please use \"getForegroundPermissionsAsync()\" or \"getBackgroundPermissionsAsync()\" instead.`\n );\n return await ExpoLocation.getPermissionsAsync();\n}\n\n// @needsAudit\n/**\n * Asks the user to grant permissions for location.\n * @return A promise that fulfills with an object of type [LocationPermissionResponse](#locationpermissionresponse).\n * @deprecated Use [`requestForegroundPermissionsAsync`](#locationrequestforegroundpermissionsasync) or [`requestBackgroundPermissionsAsync`](#locationrequestbackgroundpermissionsasync) instead.\n */\nexport async function requestPermissionsAsync(): Promise<LocationPermissionResponse> {\n console.warn(\n `\"requestPermissionsAsync()\" is now deprecated. Please use \"requestForegroundPermissionsAsync()\" or \"requestBackgroundPermissionsAsync()\" instead.`\n );\n\n return await ExpoLocation.requestPermissionsAsync();\n}\n\n// @needsAudit\n/**\n * Checks user's permissions for accessing location while the app is in the foreground.\n * @return A promise that fulfills with an object of type [PermissionResponse](#permissionresponse).\n */\nexport async function getForegroundPermissionsAsync(): Promise<LocationPermissionResponse> {\n return await ExpoLocation.getForegroundPermissionsAsync();\n}\n\n// @needsAudit\n/**\n * Asks the user to grant permissions for location while the app is in the foreground.\n * @return A promise that fulfills with an object of type [PermissionResponse](#permissionresponse).\n */\nexport async function requestForegroundPermissionsAsync(): Promise<LocationPermissionResponse> {\n return await ExpoLocation.requestForegroundPermissionsAsync();\n}\n\n// @needsAudit\n/**\n * Check or request permissions for the foreground location.\n * This uses both `requestForegroundPermissionsAsync` and `getForegroundPermissionsAsync` to interact with the permissions.\n *\n * @example\n * ```ts\n * const [status, requestPermission] = Location.useForegroundPermissions();\n * ```\n */\nexport const useForegroundPermissions = createPermissionHook({\n getMethod: getForegroundPermissionsAsync,\n requestMethod: requestForegroundPermissionsAsync,\n});\n\n// @needsAudit\n/**\n * Checks user's permissions for accessing location while the app is in the background.\n * @return A promise that fulfills with an object of type [PermissionResponse](#permissionresponse).\n */\nexport async function getBackgroundPermissionsAsync(): Promise<PermissionResponse> {\n return await ExpoLocation.getBackgroundPermissionsAsync();\n}\n\n// @needsAudit\n/**\n * Asks the user to grant permissions for location while the app is in the background.\n * On __Android 11 or higher__: this method will open the system settings page - before that happens\n * you should explain to the user why your application needs background location permission.\n * For example, you can use `Modal` component from `react-native` to do that.\n * > __Note__: Foreground permissions should be granted before asking for the background permissions\n * (your app can't obtain background permission without foreground permission).\n * @return A promise that fulfills with an object of type [PermissionResponse](#permissionresponse).\n */\nexport async function requestBackgroundPermissionsAsync(): Promise<PermissionResponse> {\n return await ExpoLocation.requestBackgroundPermissionsAsync();\n}\n\n// @needsAudit\n/**\n * Check or request permissions for the background location.\n * This uses both `requestBackgroundPermissionsAsync` and `getBackgroundPermissionsAsync` to\n * interact with the permissions.\n *\n * @example\n * ```ts\n * const [status, requestPermission] = Location.useBackgroundPermissions();\n * ```\n */\nexport const useBackgroundPermissions = createPermissionHook({\n getMethod: getBackgroundPermissionsAsync,\n requestMethod: requestBackgroundPermissionsAsync,\n});\n\n// --- Location service\n\n// @needsAudit\n/**\n * Checks whether location services are enabled by the user.\n * @return A promise which fulfills to `true` if location services are enabled on the device,\n * or `false` if not.\n */\nexport async function hasServicesEnabledAsync(): Promise<boolean> {\n return await ExpoLocation.hasServicesEnabledAsync();\n}\n\n// --- Background location updates\n\nfunction _validateTaskName(taskName: string) {\n if (!taskName || typeof taskName !== 'string') {\n throw new Error(`\\`taskName\\` must be a non-empty string. Got ${taskName} instead.`);\n }\n}\n\n// @docsMissing\nexport async function isBackgroundLocationAvailableAsync(): Promise<boolean> {\n const providerStatus = await getProviderStatusAsync();\n return providerStatus.backgroundModeEnabled;\n}\n\n// @needsAudit\n/**\n * Registers for receiving location updates that can also come when the app is in the background.\n *\n * # Task parameters\n *\n * Background location task will be receiving following data:\n * - `locations` - An array of the new locations.\n *\n * ```ts\n * import * as TaskManager from 'expo-task-manager';\n *\n * TaskManager.defineTask(YOUR_TASK_NAME, ({ data: { locations }, error }) => {\n * if (error) {\n * // check `error.message` for more details.\n * return;\n * }\n * console.log('Received new locations', locations);\n * });\n * ```\n *\n * @param taskName Name of the task receiving location updates.\n * @param options An object of options passed to the location manager.\n *\n * @return A promise resolving once the task with location updates is registered.\n */\nexport async function startLocationUpdatesAsync(\n taskName: string,\n options: LocationTaskOptions = { accuracy: LocationAccuracy.Balanced }\n): Promise<void> {\n _validateTaskName(taskName);\n await ExpoLocation.startLocationUpdatesAsync(taskName, options);\n}\n\n// @needsAudit\n/**\n * Stops geofencing for specified task.\n * @param taskName Name of the background location task to stop.\n * @return A promise resolving as soon as the task is unregistered.\n */\nexport async function stopLocationUpdatesAsync(taskName: string): Promise<void> {\n _validateTaskName(taskName);\n await ExpoLocation.stopLocationUpdatesAsync(taskName);\n}\n\n// @needsAudit\n/**\n * @param taskName Name of the location task to check.\n * @return A promise which fulfills with boolean value indicating whether the location task is\n * started or not.\n */\nexport async function hasStartedLocationUpdatesAsync(taskName: string): Promise<boolean> {\n _validateTaskName(taskName);\n return ExpoLocation.hasStartedLocationUpdatesAsync(taskName);\n}\n\n// --- Geofencing\n\nfunction _validateRegions(regions: LocationRegion[]) {\n if (!regions || regions.length === 0) {\n throw new Error(\n 'Regions array cannot be empty. Use `stopGeofencingAsync` if you want to stop geofencing all regions'\n );\n }\n for (const region of regions) {\n if (typeof region.latitude !== 'number') {\n throw new TypeError(`Region's latitude must be a number. Got '${region.latitude}' instead.`);\n }\n if (typeof region.longitude !== 'number') {\n throw new TypeError(\n `Region's longitude must be a number. Got '${region.longitude}' instead.`\n );\n }\n if (typeof region.radius !== 'number') {\n throw new TypeError(`Region's radius must be a number. Got '${region.radius}' instead.`);\n }\n }\n}\n\n// @needsAudit\n/**\n * Starts geofencing for given regions. When the new event comes, the task with specified name will\n * be called with the region that the device enter to or exit from.\n * If you want to add or remove regions from already running geofencing task, you can just call\n * `startGeofencingAsync` again with the new array of regions.\n *\n * # Task parameters\n *\n * Geofencing task will be receiving following data:\n * - `eventType` - Indicates the reason for calling the task, which can be triggered by entering or exiting the region.\n * See [GeofencingEventType](#geofencingeventtype).\n * - `region` - Object containing details about updated region. See [LocationRegion](#locationregion) for more details.\n *\n * @param taskName Name of the task that will be called when the device enters or exits from specified regions.\n * @param regions Array of region objects to be geofenced.\n *\n * @return A promise resolving as soon as the task is registered.\n *\n * @example\n * ```ts\n * import { GeofencingEventType } from 'expo-location';\n * import * as TaskManager from 'expo-task-manager';\n *\n * TaskManager.defineTask(YOUR_TASK_NAME, ({ data: { eventType, region }, error }) => {\n * if (error) {\n * // check `error.message` for more details.\n * return;\n * }\n * if (eventType === GeofencingEventType.Enter) {\n * console.log(\"You've entered region:\", region);\n * } else if (eventType === GeofencingEventType.Exit) {\n * console.log(\"You've left region:\", region);\n * }\n * });\n * ```\n */\nexport async function startGeofencingAsync(\n taskName: string,\n regions: LocationRegion[] = []\n): Promise<void> {\n _validateTaskName(taskName);\n _validateRegions(regions);\n await ExpoLocation.startGeofencingAsync(taskName, { regions });\n}\n\n// @needsAudit\n/**\n * Stops geofencing for specified task. It unregisters the background task so the app will not be\n * receiving any updates, especially in the background.\n * @param taskName Name of the task to unregister.\n * @return A promise resolving as soon as the task is unregistered.\n */\nexport async function stopGeofencingAsync(taskName: string): Promise<void> {\n _validateTaskName(taskName);\n await ExpoLocation.stopGeofencingAsync(taskName);\n}\n\n// @needsAudit\n/**\n * @param taskName Name of the geofencing task to check.\n * @return A promise which fulfills with boolean value indicating whether the geofencing task is\n * started or not.\n */\nexport async function hasStartedGeofencingAsync(taskName: string): Promise<boolean> {\n _validateTaskName(taskName);\n return ExpoLocation.hasStartedGeofencingAsync(taskName);\n}\n\nexport { LocationEventEmitter as EventEmitter, _getCurrentWatchId };\n\nexport {\n LocationAccuracy as Accuracy,\n LocationActivityType as ActivityType,\n LocationGeofencingEventType as GeofencingEventType,\n LocationGeofencingRegionState as GeofencingRegionState,\n PermissionStatus,\n PermissionHookOptions,\n setGoogleApiKey,\n};\n\nexport { installWebGeolocationPolyfill } from './GeolocationPolyfill';\nexport * from './Location.types';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-location",
3
- "version": "15.3.0",
3
+ "version": "16.1.0",
4
4
  "description": "Allows reading geolocation information from the device. Your app can poll for the current location or subscribe to location update events.",
5
5
  "main": "build/Location.js",
6
6
  "types": "build/Location.d.ts",
@@ -44,5 +44,5 @@
44
44
  "peerDependencies": {
45
45
  "expo": "*"
46
46
  },
47
- "gitHead": "3ccd2edee9cbfed217557675cb50f0ba5e55a9e4"
47
+ "gitHead": "091c7777c1cc1298826b0a5c2c35e0e201d083ed"
48
48
  }
package/src/Location.ts CHANGED
@@ -28,13 +28,16 @@ import {
28
28
  LocationGeocodingOptions,
29
29
  } from './Location.types';
30
30
  import { LocationEventEmitter } from './LocationEventEmitter';
31
- import {
32
- setGoogleApiKey,
33
- googleGeocodeAsync,
34
- googleReverseGeocodeAsync,
35
- } from './LocationGoogleGeocoding';
36
31
  import { LocationSubscriber, HeadingSubscriber, _getCurrentWatchId } from './LocationSubscribers';
37
32
 
33
+ // @needsAudit
34
+ /**
35
+ * @deprecated The Geocoding web api is no longer available from SDK 49 onwards. Use [Place Autocomplete](https://developers.google.com/maps/documentation/places/web-service/autocomplete) instead.
36
+ * @param apiKey Google API key obtained from Google API Console. This API key must have `Geocoding API`
37
+ * enabled, otherwise your geocoding requests will be denied.
38
+ */
39
+ function setGoogleApiKey(_apiKey: string) {}
40
+
38
41
  // @needsAudit
39
42
  /**
40
43
  * Check status of location providers.
@@ -163,6 +166,8 @@ export async function watchHeadingAsync(
163
166
  // @needsAudit
164
167
  /**
165
168
  * Geocode an address string to latitude-longitude location.
169
+ * > **Note**: Using the Geocoding web api is no longer supported. Use [Place Autocomplete](https://developers.google.com/maps/documentation/places/web-service/autocomplete) instead.
170
+ *
166
171
  * > **Note**: Geocoding is resource consuming and has to be used reasonably. Creating too many
167
172
  * > requests at a time can result in an error, so they have to be managed properly.
168
173
  * > It's also discouraged to use geocoding while the app is in the background and its results won't
@@ -181,15 +186,25 @@ export async function geocodeAsync(
181
186
  if (typeof address !== 'string') {
182
187
  throw new TypeError(`Address to geocode must be a string. Got ${address} instead.`);
183
188
  }
189
+
184
190
  if (options?.useGoogleMaps || Platform.OS === 'web') {
185
- return await googleGeocodeAsync(address);
191
+ if (__DEV__) {
192
+ console.warn(
193
+ 'The Geocoding API has been removed in SDK 49, use Place Autocomplete service instead' +
194
+ '(https://developers.google.com/maps/documentation/places/web-service/autocomplete)'
195
+ );
196
+ }
197
+ return [];
186
198
  }
199
+
187
200
  return await ExpoLocation.geocodeAsync(address);
188
201
  }
189
202
 
190
203
  // @needsAudit
191
204
  /**
192
205
  * Reverse geocode a location to postal address.
206
+ * > **Note**: Using the Geocoding web api is no longer supported. Use [Place Autocomplete](https://developers.google.com/maps/documentation/places/web-service/autocomplete) instead.
207
+ *
193
208
  * > **Note**: Geocoding is resource consuming and has to be used reasonably. Creating too many
194
209
  * > requests at a time can result in an error, so they have to be managed properly.
195
210
  * > It's also discouraged to use geocoding while the app is in the background and its results won't
@@ -210,9 +225,17 @@ export async function reverseGeocodeAsync(
210
225
  'Location to reverse-geocode must be an object with number properties `latitude` and `longitude`.'
211
226
  );
212
227
  }
228
+
213
229
  if (options?.useGoogleMaps || Platform.OS === 'web') {
214
- return await googleReverseGeocodeAsync(location);
230
+ if (__DEV__) {
231
+ console.warn(
232
+ 'The Geocoding API has been removed in SDK 49, use Place Autocomplete service instead' +
233
+ '(https://developers.google.com/maps/documentation/places/web-service/autocomplete)'
234
+ );
235
+ }
236
+ return [];
215
237
  }
238
+
216
239
  return await ExpoLocation.reverseGeocodeAsync(location);
217
240
  }
218
241
 
@@ -1,16 +0,0 @@
1
- import { LocationGeocodedAddress, LocationGeocodedLocation } from './Location.types';
2
- /**
3
- * Sets a Google API Key for using Google Maps Geocoding API which is used by default on Web
4
- * platform and can be enabled through `useGoogleMaps` option of `geocodeAsync` and `reverseGeocodeAsync`
5
- * methods. It might be useful for Android devices that do not have Google Play Services, hence no
6
- * Geocoder Service.
7
- * @param apiKey Google API key obtained from Google API Console. This API key must have `Geocoding API`
8
- * enabled, otherwise your geocoding requests will be denied.
9
- */
10
- export declare function setGoogleApiKey(apiKey: string): void;
11
- export declare function googleGeocodeAsync(address: string): Promise<LocationGeocodedLocation[]>;
12
- export declare function googleReverseGeocodeAsync(options: {
13
- latitude: number;
14
- longitude: number;
15
- }): Promise<LocationGeocodedAddress[]>;
16
- //# sourceMappingURL=LocationGoogleGeocoding.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LocationGoogleGeocoding.d.ts","sourceRoot":"","sources":["../src/LocationGoogleGeocoding.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AA4BrF;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,QAE7C;AAED,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,EAAE,CAAC,CAU7F;AAED,wBAAsB,yBAAyB,CAAC,OAAO,EAAE;IACvD,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAYrC"}
@@ -1,126 +0,0 @@
1
- import { CodedError } from 'expo-modules-core';
2
- const GOOGLE_API_URL = 'https://maps.googleapis.com/maps/api/geocode/json';
3
- let googleApiKey;
4
- // @needsAudit
5
- /**
6
- * Sets a Google API Key for using Google Maps Geocoding API which is used by default on Web
7
- * platform and can be enabled through `useGoogleMaps` option of `geocodeAsync` and `reverseGeocodeAsync`
8
- * methods. It might be useful for Android devices that do not have Google Play Services, hence no
9
- * Geocoder Service.
10
- * @param apiKey Google API key obtained from Google API Console. This API key must have `Geocoding API`
11
- * enabled, otherwise your geocoding requests will be denied.
12
- */
13
- export function setGoogleApiKey(apiKey) {
14
- googleApiKey = apiKey;
15
- }
16
- export async function googleGeocodeAsync(address) {
17
- assertGoogleApiKey();
18
- const result = await requestGoogleApiAsync({ address });
19
- if (result.status === 'ZERO_RESULTS') {
20
- return [];
21
- }
22
- assertGeocodeResults(result);
23
- return result.results.map(geocodingResultToLocation);
24
- }
25
- export async function googleReverseGeocodeAsync(options) {
26
- assertGoogleApiKey();
27
- const result = await requestGoogleApiAsync({
28
- latlng: `${options.latitude},${options.longitude}`,
29
- });
30
- if (result.status === 'ZERO_RESULTS') {
31
- return [];
32
- }
33
- assertGeocodeResults(result);
34
- return result.results.map(reverseGeocodingResultToAddress);
35
- }
36
- // https://developers.google.com/maps/documentation/geocoding/intro
37
- function assertGeocodeResults(resultObject) {
38
- const { status, error_message } = resultObject;
39
- if (status !== 'ZERO_RESULTS' && status !== 'OK') {
40
- if (error_message) {
41
- throw new CodedError(status, error_message);
42
- }
43
- else if (status === 'UNKNOWN_ERROR') {
44
- throw new CodedError(status, 'the request could not be processed due to a server error. The request may succeed if you try again.');
45
- }
46
- throw new CodedError(status, `An error occurred during geocoding.`);
47
- }
48
- }
49
- /**
50
- * Makes sure the Google API key is set.
51
- */
52
- function assertGoogleApiKey() {
53
- if (!googleApiKey) {
54
- throw new Error('Google API key is required to use geocoding. Please set it using `setGoogleApiKey` method.');
55
- }
56
- }
57
- /**
58
- * Generic and handy method for sending requests to Google Maps API endpoint.
59
- */
60
- async function requestGoogleApiAsync(params) {
61
- const query = Object.entries(params)
62
- .map((entry) => `${entry[0]}=${encodeURI(entry[1])}`)
63
- .join('&');
64
- const result = await fetch(`${GOOGLE_API_URL}?key=${googleApiKey}&${query}`);
65
- return await result.json();
66
- }
67
- /**
68
- * Converts Google's result to the location object.
69
- */
70
- function geocodingResultToLocation(result) {
71
- const { location } = result.geometry;
72
- return {
73
- latitude: location.lat,
74
- longitude: location.lng,
75
- };
76
- }
77
- /**
78
- * Converts Google's result to address object.
79
- */
80
- function reverseGeocodingResultToAddress(result) {
81
- const address = {};
82
- for (const { long_name, short_name, types } of result.address_components) {
83
- if (types.includes('locality')) {
84
- address.city = long_name;
85
- continue;
86
- }
87
- if (types.includes('sublocality')) {
88
- address.district = long_name;
89
- continue;
90
- }
91
- if (types.includes('street_number')) {
92
- address.streetNumber = long_name;
93
- continue;
94
- }
95
- if (types.includes('street_address') || types.includes('route')) {
96
- address.street = long_name;
97
- continue;
98
- }
99
- if (types.includes('administrative_area_level_1')) {
100
- address.region = long_name;
101
- continue;
102
- }
103
- if (types.includes('administrative_area_level_2')) {
104
- address.subregion = long_name;
105
- continue;
106
- }
107
- if (types.includes('country')) {
108
- address.country = long_name;
109
- address.isoCountryCode = short_name;
110
- continue;
111
- }
112
- if (types.includes('postal_code')) {
113
- address.postalCode = long_name;
114
- continue;
115
- }
116
- if (types.includes('point_of_interest')) {
117
- address.name = long_name;
118
- continue;
119
- }
120
- }
121
- if (!address.name) {
122
- address.name = result.formatted_address.replace(/,.*$/, '');
123
- }
124
- return address;
125
- }
126
- //# sourceMappingURL=LocationGoogleGeocoding.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LocationGoogleGeocoding.js","sourceRoot":"","sources":["../src/LocationGoogleGeocoding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI/C,MAAM,cAAc,GAAG,mDAAmD,CAAC;AAC3E,IAAI,YAAY,CAAC;AAwBjB,cAAc;AACd;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,MAAc;IAC5C,YAAY,GAAG,MAAM,CAAC;AACxB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,OAAe;IACtD,kBAAkB,EAAE,CAAC;IAErB,MAAM,MAAM,GAAG,MAAM,qBAAqB,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;IAExD,IAAI,MAAM,CAAC,MAAM,KAAK,cAAc,EAAE;QACpC,OAAO,EAAE,CAAC;KACX;IACD,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC7B,OAAO,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,MAAM,GAAG,SAAS,CAAC;YAC3B,SAAS;SACV;QACD,IAAI,KAAK,CAAC,QAAQ,CAAC,6BAA6B,CAAC,EAAE;YACjD,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;YAC9B,SAAS;SACV;QACD,IAAI,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;YAC7B,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;YAC5B,OAAO,CAAC,cAAc,GAAG,UAAU,CAAC;YACpC,SAAS;SACV;QACD,IAAI,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE;YACjC,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;YAC/B,SAAS;SACV;QACD,IAAI,KAAK,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE;YACvC,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC;YACzB,SAAS;SACV;KACF;IACD,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;QACjB,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,iBAAiB,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;KAC7D;IACD,OAAO,OAAkC,CAAC;AAC5C,CAAC","sourcesContent":["import { CodedError } from 'expo-modules-core';\n\nimport { LocationGeocodedAddress, LocationGeocodedLocation } from './Location.types';\n\nconst GOOGLE_API_URL = 'https://maps.googleapis.com/maps/api/geocode/json';\nlet googleApiKey;\n\ntype GoogleApiGeocodingAddressComponent = {\n long_name: string;\n short_name: string;\n types: string[];\n};\n\ntype GoogleApiGeocodingResult = {\n address_components: GoogleApiGeocodingAddressComponent[];\n formatted_address: string;\n geometry: {\n location: {\n lat: number;\n lng: number;\n };\n };\n};\n\ntype GoogleApiGeocodingResponse = {\n results: GoogleApiGeocodingResult[];\n status: string;\n};\n\n// @needsAudit\n/**\n * Sets a Google API Key for using Google Maps Geocoding API which is used by default on Web\n * platform and can be enabled through `useGoogleMaps` option of `geocodeAsync` and `reverseGeocodeAsync`\n * methods. It might be useful for Android devices that do not have Google Play Services, hence no\n * Geocoder Service.\n * @param apiKey Google API key obtained from Google API Console. This API key must have `Geocoding API`\n * enabled, otherwise your geocoding requests will be denied.\n */\nexport function setGoogleApiKey(apiKey: string) {\n googleApiKey = apiKey;\n}\n\nexport async function googleGeocodeAsync(address: string): Promise<LocationGeocodedLocation[]> {\n assertGoogleApiKey();\n\n const result = await requestGoogleApiAsync({ address });\n\n if (result.status === 'ZERO_RESULTS') {\n return [];\n }\n assertGeocodeResults(result);\n return result.results.map(geocodingResultToLocation);\n}\n\nexport async function googleReverseGeocodeAsync(options: {\n latitude: number;\n longitude: number;\n}): Promise<LocationGeocodedAddress[]> {\n assertGoogleApiKey();\n\n const result = await requestGoogleApiAsync({\n latlng: `${options.latitude},${options.longitude}`,\n });\n\n if (result.status === 'ZERO_RESULTS') {\n return [];\n }\n assertGeocodeResults(result);\n return result.results.map(reverseGeocodingResultToAddress);\n}\n\n// https://developers.google.com/maps/documentation/geocoding/intro\nfunction assertGeocodeResults(resultObject: any): void {\n const { status, error_message } = resultObject;\n if (status !== 'ZERO_RESULTS' && status !== 'OK') {\n if (error_message) {\n throw new CodedError(status, error_message);\n } else if (status === 'UNKNOWN_ERROR') {\n throw new CodedError(\n status,\n 'the request could not be processed due to a server error. The request may succeed if you try again.'\n );\n }\n throw new CodedError(status, `An error occurred during geocoding.`);\n }\n}\n\n/**\n * Makes sure the Google API key is set.\n */\nfunction assertGoogleApiKey() {\n if (!googleApiKey) {\n throw new Error(\n 'Google API key is required to use geocoding. Please set it using `setGoogleApiKey` method.'\n );\n }\n}\n\n/**\n * Generic and handy method for sending requests to Google Maps API endpoint.\n */\nasync function requestGoogleApiAsync(\n params: { address: string } | { latlng: string }\n): Promise<GoogleApiGeocodingResponse> {\n const query = Object.entries(params)\n .map((entry) => `${entry[0]}=${encodeURI(entry[1])}`)\n .join('&');\n const result = await fetch(`${GOOGLE_API_URL}?key=${googleApiKey}&${query}`);\n return await result.json();\n}\n\n/**\n * Converts Google's result to the location object.\n */\nfunction geocodingResultToLocation(result: GoogleApiGeocodingResult): LocationGeocodedLocation {\n const { location } = result.geometry;\n return {\n latitude: location.lat,\n longitude: location.lng,\n };\n}\n\n/**\n * Converts Google's result to address object.\n */\nfunction reverseGeocodingResultToAddress(\n result: GoogleApiGeocodingResult\n): LocationGeocodedAddress {\n const address: Partial<LocationGeocodedAddress> = {};\n\n for (const { long_name, short_name, types } of result.address_components) {\n if (types.includes('locality')) {\n address.city = long_name;\n continue;\n }\n if (types.includes('sublocality')) {\n address.district = long_name;\n continue;\n }\n if (types.includes('street_number')) {\n address.streetNumber = long_name;\n continue;\n }\n if (types.includes('street_address') || types.includes('route')) {\n address.street = long_name;\n continue;\n }\n if (types.includes('administrative_area_level_1')) {\n address.region = long_name;\n continue;\n }\n if (types.includes('administrative_area_level_2')) {\n address.subregion = long_name;\n continue;\n }\n if (types.includes('country')) {\n address.country = long_name;\n address.isoCountryCode = short_name;\n continue;\n }\n if (types.includes('postal_code')) {\n address.postalCode = long_name;\n continue;\n }\n if (types.includes('point_of_interest')) {\n address.name = long_name;\n continue;\n }\n }\n if (!address.name) {\n address.name = result.formatted_address.replace(/,.*$/, '');\n }\n return address as LocationGeocodedAddress;\n}\n"]}
@@ -1,174 +0,0 @@
1
- import { CodedError } from 'expo-modules-core';
2
-
3
- import { LocationGeocodedAddress, LocationGeocodedLocation } from './Location.types';
4
-
5
- const GOOGLE_API_URL = 'https://maps.googleapis.com/maps/api/geocode/json';
6
- let googleApiKey;
7
-
8
- type GoogleApiGeocodingAddressComponent = {
9
- long_name: string;
10
- short_name: string;
11
- types: string[];
12
- };
13
-
14
- type GoogleApiGeocodingResult = {
15
- address_components: GoogleApiGeocodingAddressComponent[];
16
- formatted_address: string;
17
- geometry: {
18
- location: {
19
- lat: number;
20
- lng: number;
21
- };
22
- };
23
- };
24
-
25
- type GoogleApiGeocodingResponse = {
26
- results: GoogleApiGeocodingResult[];
27
- status: string;
28
- };
29
-
30
- // @needsAudit
31
- /**
32
- * Sets a Google API Key for using Google Maps Geocoding API which is used by default on Web
33
- * platform and can be enabled through `useGoogleMaps` option of `geocodeAsync` and `reverseGeocodeAsync`
34
- * methods. It might be useful for Android devices that do not have Google Play Services, hence no
35
- * Geocoder Service.
36
- * @param apiKey Google API key obtained from Google API Console. This API key must have `Geocoding API`
37
- * enabled, otherwise your geocoding requests will be denied.
38
- */
39
- export function setGoogleApiKey(apiKey: string) {
40
- googleApiKey = apiKey;
41
- }
42
-
43
- export async function googleGeocodeAsync(address: string): Promise<LocationGeocodedLocation[]> {
44
- assertGoogleApiKey();
45
-
46
- const result = await requestGoogleApiAsync({ address });
47
-
48
- if (result.status === 'ZERO_RESULTS') {
49
- return [];
50
- }
51
- assertGeocodeResults(result);
52
- return result.results.map(geocodingResultToLocation);
53
- }
54
-
55
- export async function googleReverseGeocodeAsync(options: {
56
- latitude: number;
57
- longitude: number;
58
- }): Promise<LocationGeocodedAddress[]> {
59
- assertGoogleApiKey();
60
-
61
- const result = await requestGoogleApiAsync({
62
- latlng: `${options.latitude},${options.longitude}`,
63
- });
64
-
65
- if (result.status === 'ZERO_RESULTS') {
66
- return [];
67
- }
68
- assertGeocodeResults(result);
69
- return result.results.map(reverseGeocodingResultToAddress);
70
- }
71
-
72
- // https://developers.google.com/maps/documentation/geocoding/intro
73
- function assertGeocodeResults(resultObject: any): void {
74
- const { status, error_message } = resultObject;
75
- if (status !== 'ZERO_RESULTS' && status !== 'OK') {
76
- if (error_message) {
77
- throw new CodedError(status, error_message);
78
- } else if (status === 'UNKNOWN_ERROR') {
79
- throw new CodedError(
80
- status,
81
- 'the request could not be processed due to a server error. The request may succeed if you try again.'
82
- );
83
- }
84
- throw new CodedError(status, `An error occurred during geocoding.`);
85
- }
86
- }
87
-
88
- /**
89
- * Makes sure the Google API key is set.
90
- */
91
- function assertGoogleApiKey() {
92
- if (!googleApiKey) {
93
- throw new Error(
94
- 'Google API key is required to use geocoding. Please set it using `setGoogleApiKey` method.'
95
- );
96
- }
97
- }
98
-
99
- /**
100
- * Generic and handy method for sending requests to Google Maps API endpoint.
101
- */
102
- async function requestGoogleApiAsync(
103
- params: { address: string } | { latlng: string }
104
- ): Promise<GoogleApiGeocodingResponse> {
105
- const query = Object.entries(params)
106
- .map((entry) => `${entry[0]}=${encodeURI(entry[1])}`)
107
- .join('&');
108
- const result = await fetch(`${GOOGLE_API_URL}?key=${googleApiKey}&${query}`);
109
- return await result.json();
110
- }
111
-
112
- /**
113
- * Converts Google's result to the location object.
114
- */
115
- function geocodingResultToLocation(result: GoogleApiGeocodingResult): LocationGeocodedLocation {
116
- const { location } = result.geometry;
117
- return {
118
- latitude: location.lat,
119
- longitude: location.lng,
120
- };
121
- }
122
-
123
- /**
124
- * Converts Google's result to address object.
125
- */
126
- function reverseGeocodingResultToAddress(
127
- result: GoogleApiGeocodingResult
128
- ): LocationGeocodedAddress {
129
- const address: Partial<LocationGeocodedAddress> = {};
130
-
131
- for (const { long_name, short_name, types } of result.address_components) {
132
- if (types.includes('locality')) {
133
- address.city = long_name;
134
- continue;
135
- }
136
- if (types.includes('sublocality')) {
137
- address.district = long_name;
138
- continue;
139
- }
140
- if (types.includes('street_number')) {
141
- address.streetNumber = long_name;
142
- continue;
143
- }
144
- if (types.includes('street_address') || types.includes('route')) {
145
- address.street = long_name;
146
- continue;
147
- }
148
- if (types.includes('administrative_area_level_1')) {
149
- address.region = long_name;
150
- continue;
151
- }
152
- if (types.includes('administrative_area_level_2')) {
153
- address.subregion = long_name;
154
- continue;
155
- }
156
- if (types.includes('country')) {
157
- address.country = long_name;
158
- address.isoCountryCode = short_name;
159
- continue;
160
- }
161
- if (types.includes('postal_code')) {
162
- address.postalCode = long_name;
163
- continue;
164
- }
165
- if (types.includes('point_of_interest')) {
166
- address.name = long_name;
167
- continue;
168
- }
169
- }
170
- if (!address.name) {
171
- address.name = result.formatted_address.replace(/,.*$/, '');
172
- }
173
- return address as LocationGeocodedAddress;
174
- }