React-native-google-places-autocomplete: Reverse Geocoding with any location?

Created on 7 Jun 2016  路  2Comments  路  Source: FaridSafi/react-native-google-places-autocomplete

Hello @myaskevich ,

With the current implementation, it seems like you can only do reverse geocoding with the current location, but is there a way to do reverse geocoding with a given place_id or longitude and latitude?

Thank you!

Most helpful comment

Hi @yangster24

I don't quite see how this library can help you do reverse geocoding by latlng/place_id.

Why not simply make a HTTP request via Google Maps REST API like so:

    let params = {
      key: 'YOUR_API_KEY',
      latlng: `${latitude},${longitude}`,
    };
    let qs = querystring.stringify(params);

    return fetch(
      `https://maps.googleapis.com/maps/api/geocode/json?${qs}`)
        .then((res) => res.json())
        .then((json) => {
          if (json.status !== 'OK') {
            throw new Error(`Geocode error: ${json.status}`);
          }
          return json;
        });
  }

All 2 comments

Hi @yangster24

I don't quite see how this library can help you do reverse geocoding by latlng/place_id.

Why not simply make a HTTP request via Google Maps REST API like so:

    let params = {
      key: 'YOUR_API_KEY',
      latlng: `${latitude},${longitude}`,
    };
    let qs = querystring.stringify(params);

    return fetch(
      `https://maps.googleapis.com/maps/api/geocode/json?${qs}`)
        .then((res) => res.json())
        .then((json) => {
          if (json.status !== 'OK') {
            throw new Error(`Geocode error: ${json.status}`);
          }
          return json;
        });
  }

@myaskevich Thank you so much! This provides a lot versatility to use various parts of Google Maps API :)

Was this page helpful?
0 / 5 - 0 ratings