Snippets Collections
// Google Maps  
function initMap(getLat, getLng) {
  const location = { lat: getLat, lng: getLng };
  // The map
  const map = new google.maps.Map(document.getElementById("map"), {
    zoom: 14,
    center: location,
  });
  // The marker
  const marker = new google.maps.Marker({
    position: location,
    map: map,
  });
}

// Geocode
function geocode() {
  var defaultLocation = 'Tbilisi';
  var address = $("#address").text();

  if (addressEn) { // You can add more conditionals to specify address line 2, zip code, etc.
    var myLocation = address;
  } else {
    var myLocation = defaultLocation
  }

  axios.get('https://maps.googleapis.com/maps/api/geocode/json',{
    params:{
      address: myLocation,
      key: 'YOUR_KEY',
    }
  })
  .then(function (response) {
    var lat = response.data.results[0].geometry.location.lat;
    var lng = response.data.results[0].geometry.location.lng;
    initMap(lat, lng);
  })
  .catch(function(error) {
    console.log(error);
  })
}
// Call
geocode();


Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension