React-native-google-places-autocomplete: Can not read property 'getCurrentPosition' of undefined

Created on 20 Jan 2020  路  1Comment  路  Source: FaridSafi/react-native-google-places-autocomplete

When I press on Current location so i get this error
Screenshot_2020-01-20_122122

Most helpful comment

Hi @RonakPatel0

I'm also getting this error, and I didn't find a way to make it work !

But I can share to you my temporary fix:

  • Geoloc the user
  • reverse geo thanks to your Google API geocode
  • use "predefinedPlaces" props to pass your object current location
getCurrentLocation() {
Geolocation.getCurrentPosition(({ coords }) => {
      console.log(coords);
      fetch('https://maps.googleapis.com/maps/api/geocode/json?address=' + coords.latitude + ',' + coords.longitude + '&key=' + myKey)
        .then((response) => {
          response.json().then((json) => {
            console.log(json.results[0]);
            this.setState({
              currentPosition: {
                data: json.results[0],
                details: json.results[0],
                description: "current location",
              }
            })
          });
        })
    })
}

and then user "predefinedPlaces" props

const GooglePlacesInput = () => {
  return (
    <GooglePlacesAutocomplete
     // [...]
      predefinedPlaces={[this.state.currentPosition]}
     // [...]
    />
  );
}

>All comments

Hi @RonakPatel0

I'm also getting this error, and I didn't find a way to make it work !

But I can share to you my temporary fix:

  • Geoloc the user
  • reverse geo thanks to your Google API geocode
  • use "predefinedPlaces" props to pass your object current location
getCurrentLocation() {
Geolocation.getCurrentPosition(({ coords }) => {
      console.log(coords);
      fetch('https://maps.googleapis.com/maps/api/geocode/json?address=' + coords.latitude + ',' + coords.longitude + '&key=' + myKey)
        .then((response) => {
          response.json().then((json) => {
            console.log(json.results[0]);
            this.setState({
              currentPosition: {
                data: json.results[0],
                details: json.results[0],
                description: "current location",
              }
            })
          });
        })
    })
}

and then user "predefinedPlaces" props

const GooglePlacesInput = () => {
  return (
    <GooglePlacesAutocomplete
     // [...]
      predefinedPlaces={[this.state.currentPosition]}
     // [...]
    />
  );
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

RajanPN picture RajanPN  路  3Comments

tezahzulueta picture tezahzulueta  路  3Comments

yashwanth15 picture yashwanth15  路  3Comments

DennisMuchiri picture DennisMuchiri  路  4Comments

akhlopyk picture akhlopyk  路  3Comments