shukerullah / react-geocode

A React module to transform a description of a location (i.e. street address, town name, etc.) into geographic coordinates (i.e. latitude and longitude) and vice versa.
MIT License
207 stars 35 forks source link

add fromPlaceId function #46

Open bicf opened 1 year ago

bicf commented 1 year ago

To allow to get geocode infos using the place_id string

shukerullah commented 1 year ago

Hi @bicf,

Thank you for your PR! I appreciate the updates to the source file. Could you also consider updating the library folder for consistency? Let me know if you need any guidance.

bicf commented 1 year ago

Hi @bicf,

Thank you for your PR! I appreciate the updates to the source file. Could you also consider updating the library folder for consistency? Let me know if you need any guidance.

Hi @shukerullah yes, absolutely! I've actually already tried to update the library folder, but I'm quite new to the node ecosystem, so a little guidance will be appreciated.

Please let me know the tool you've used to build the lib file.

shukerullah commented 1 year ago

Thanks @bicf and @ivan-redooc for your start on this! I've further enhanced the changes and merged the PR. Could you test it with a fromPlaceId and confirm if it's good to go? If so, can I request closing the ticket?

Here's an example of how to use it:

import { setDefaults, fromPlaceId } from 'react-geocode';

setDefaults({
  key: 'YOUR_API_KEY', // Replace with your API key
  language: 'en', // Default language for responses
  region: 'es' // Default region for responses
});

fromPlaceId('ChIJd8BlQ2BZwokRAFUEcm_qrcA')
  .then(({ results }) => {
    const { lat, lng } = results[0].geometry.location;
    console.log(lat, lng);
  })
  .catch(console.error);

Appreciate your help! 😊

bicf commented 1 year ago

Thanks @bicf and @ivan-redooc for your start on this! I've further enhanced the changes and merged the PR. Could you test it with a fromPlaceId and confirm if it's good to go? If so, can I request closing the ticket?

Yes

The sample code is correct!