location permission in `expo-location` module

Please provide the following:

  1. SDK Version: 41
  2. Platforms(Android/iOS/web/all): Android, iOS
  3. Add the appropriate “Tag” based on what Expo library you have a question on.

Hi, I have 2 questions related to expo-location module:

  1. due to the docs Location - Expo Documentation we must request Permissions.LOCATION on android. And the question is: why do we must to request it?
    In case we use google-maps-api
export async function geocodeAsync(
  address: string,
  options?: LocationGeocodingOptions
): Promise<LocationGeocodedLocation[]> {
  if (typeof address !== 'string') {
    throw new TypeError(`Address to geocode must be a string. Got ${address} instead.`);
  }
  if (options?.useGoogleMaps || Platform.OS === 'web') {
    return await googleGeocodeAsync(address);
  }
  return await ExpoLocation.geocodeAsync(address);
}

googleGeocodeAsync is all about sending request and receiving data. So what will happen if there is no Permissions.LOCATION? Could we be sure that module will work fine even without Permissions.LOCATION?

  1. in case we use native implementation the code for android looks like:
@ExpoMethod
  public void geocodeAsync(final String address, final Promise promise) {
    if (mGeocoderPaused) {
      promise.reject("E_CANNOT_GEOCODE", "Geocoder is not running.");
      return;
    }

    if (isMissingForegroundPermissions()) {
       promise.reject(new LocationUnauthorizedException());
       return;
    }

    if (Geocoder.isPresent()) {
      SmartLocation.with(mContext).geocoding()
        .direct(address, (s, list) -> {
          List<Bundle> results = new ArrayList<>(list.size());

          for (LocationAddress locationAddress : list) {
            Bundle coords = LocationHelpers.locationToCoordsBundle(locationAddress.getLocation(), Bundle.class);

            if (coords != null) {
              results.add(coords);
            }
          }

          SmartLocation.with(mContext).geocoding().stop();
          promise.resolve(results);
        });
    } else {
      promise.reject("E_NO_GEOCODER", "Geocoder service is not available for this device.");
    }
  }

What will happen if we comment/remove isMissingForegroundPermissions part?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.