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 33 forks source link

Doesn't exist setLocationType method #44

Closed SoriaDamian17 closed 11 months ago

SoriaDamian17 commented 2 years ago

I cannot use Geocode.setLocationType("ROOFTOP");

shukerullah commented 11 months ago

Hi there!

Thank you for bringing this issue to our attention. I've successfully resolved it by utilizing setLocationType("ROOFTOP"). Here's an example of how you can use it in your code:

import {
  setKey,
  geocode,
  setLocationType,
  RequestType,
  fromLatLng,
} from 'react-geocode';

setKey('YOUR_API_KEY'); // Replace with your API key

setLocationType('ROOFTOP');

geocode(RequestType.LATLNG, '48.8583701,2.2922926')
  .then(({results}) => {
    const address = results[0].formatted_address;
    console.log(address);
  })
  .catch(console.error);

// OR
fromLatLng(48.8583701, 2.2922926)
  .then(({results}) => {
    const {lat, lng} = results[0].geometry.location;
    console.log(lat, lng);
  })
  .catch(console.error);

Feel free to reach out if you have any further questions or concerns. Thanks again for your contribution!