Expo GooglePlacesAutocomplete currentLocation not working on iOS

442 Views Asked by At

In Expo I'm using GooglePlacesAutocomplete, and I'm trying to add the current location label. It's interesting because in Android it works with the react-native-geolocation-service, but in iOS it doesn't. Here's my code:

import { GooglePlacesAutocomplete } from "react-native-google-places-autocomplete";
navigator.geolocation = require("react-native-geolocation-service");
const chooseOrigin = () => {
  return (
    <View>
      <GooglePlacesAutocomplete
        placeholder="Choose origin"
        fetchDetails={true}
        autoFocus={true}
        currentLocation={true}
        currentLocationLabel="My location"
        textInputProps={{
          placeholderTextColor: "#ccc",
          autoFocus: true,
        }}
        onPress={(data, details = null) => {
            console.log(data, details);
          }}
   />
export default chooseOrigin;

Adding this line:

navigator.geolocation = require("react-native-geolocation-service");

Throws this error but only on iOS Simulator:

[iOS Simulator Error][1]

Tried with "@react-native-community/geolocation" like documentation says but got error on both, Android and iOS Simulator. Changed line to:

navigator.geolocation = require('@react-native-community/geolocation');

and got this error: Error in iOS and Android

Don't understand yet if i'm missing something or the documentation isn't updated. Please help.

1

There are 1 best solutions below

1
youcefker On

navigator.geolocation = require("expo-location") worked for me.

navigator.geolocation = require("react-native-geolocation-service") OR navigator.geolocation = require('@react-native-community/geolocation')

need pods configurations for IOS .