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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.