Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to use Node.js Client for Google Maps Services for geolocation

const maps = new Client({});
 const geocode = async (address: string) => {
    const res = await maps.geocode({
      params: {
        address,
        key: `${process.env.GOOGLE_MAPS_API_KEY}`,
      },
      timeout: 1000, // milliseconds
    });

    if (res.status < 200 || res.status > 299 ) {
      throw new Error(res.data.error_message);
    }

    return res.data.results[0]..address_components;
  },
 
PREVIOUS NEXT
Tagged: #Client #Google #Maps #Services #geolocation
ADD COMMENT
Topic
Name
8+7 =