const googleApiUrl = 'https://maps.google.com/maps/api/geocode/json';

export default {
  apiKey: null,

  setApiKey(apiKey) {
    this.apiKey = apiKey;
  },

  async getFromLocation(address) {
    if (!this.apiKey) {
      return Promise.reject(new Error("Provided API key is invalid"));
    }

    if (!address) {
      return Promise.reject(new Error("Provided address is invalid"));
    }

    const url = `${googleApiUrl}?key=${this.apiKey}&address=${encodeURI(address)}`;
    const response = await fetch(url).catch(
      error => {
        return Promise.reject(new Error("Error fetching data"));
      }
    );

    const json = await response.json().catch(
      error => {
        return Promise.reject(new Error("Error parsing server response"));
      }
    );

    if (json.status === 'OK') {
      return json;
    }
    else {
      return Promise.reject(new Error(`Server returned status code ${json.status}`));
    }
  }
}
@@ -152,16 +152,792 @@
 ;%0A  %7D,%0A%0A
+  async getFromLatLng(latLng) %7B%0A    if (!this.apiKey) %7B%0A      return Promise.reject(new Error(%22Provided API key is invalid%22));%0A    %7D%0A%0A    if (!latLng) %7B%0A      return Promise.reject(new Error(%22Provided lat lng is invalid%22));%0A    %7D%0A%0A    const url = %60$%7BgoogleApiUrl%7D?key=$%7Bthis.apiKey%7D&latlng=$%7BencodeURI(latLng)%7D%60;%0A    const response = await fetch(url).catch(%0A      error =%3E %7B%0A        return Promise.reject(new Error(%22Error fetching data%22));%0A      %7D%0A    );%0A%0A    const json = await response.json().catch(%0A      error =%3E %7B%0A        return Promise.reject(new Error(%22Error parsing server response%22));%0A      %7D%0A    );%0A%0A    if (json.status === 'OK') %7B%0A      return json;%0A    %7D%0A    else %7B%0A      return Promise.reject(new Error(%60Server returned status code $%7Bjson.status%7D%60));%0A    %7D%0A  %7D,%0A%0A
   async 
@@ -1709,8 +1709,9 @@
  %7D%0A  %7D%0A%7D
+%0A

Add Reverse Geolocation Lookup