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

Please improve the component filtering and add the postal_code feature #42

Closed NicoSan20 closed 1 year ago

NicoSan20 commented 3 years ago

Hi,

In the Geocoding of google, you have now the possibility to do a restriction on the postal code.

You can append this like that : components=country:CH|postal_code:8000

Here the documentation from Google : Geocoding FAQ

This will feature will be appreciate...

Thank you in advance and sorry for my english, I speak only french.

Regards

shukerullah commented 1 year ago

Hello,

Thank you for your suggestion! In the latest version, we've introduced a setComponents method that allows you to set postal code restrictions. Feel free to give it a try.

import {setKey, setComponents, fromAddress} from 'react-geocode';

setKey('AIzaSyDUAzKPR3MoFHwZz7wEYThVptNvnq_cBJY');

setComponents('locality:santa+cruz|country:ES');

fromAddress('high st hasting')
  .then(({results}) => {
    console.log(results);
  })
  .catch(console.error);
import {setKey, geocode} from 'react-geocode';

setKey('AIzaSyDUAzKPR3MoFHwZz7wEYThVptNvnq_cBJY');

geocode('components', 'locality:santa+cruz|country:ES')
  .then(({results}) => {
    console.log(results);
  })
  .catch(console.error);

If you have further questions or need assistance, don't hesitate to ask.