Get started with gmaps.js CDN

MIT licensed

Gmaps.js is a library for using Google Maps in web applications.

Tags:
  • google maps
  • maps

Stable version

Copied!

How to start using gmaps.js CDN


// Include the Google Maps API script
const script = document.createElement('script');
script.src = 'https://cdn.cdnhub.io/gmaps.js/0.4.25/gmaps.min.js';
document.head.appendChild(script);

// Wait for the API to load before initializing the map
window.onLoad = function() {
  if (google.maps && typeof google.maps.Map === 'function') {
    // Initialize the map
    const map = new google.maps.Map(document.createElement('div'), {
      center: {lat: 40.7128, lng: -74.0060}, // New York City coordinates
      zoom: 12
    });

    document.body.appendChild(map.getDiv());

    // Create a marker
    new google.maps.Marker({
      position: {lat: 40.7128, lng: -74.0060},
      map: map
    });
  }
};
Copied!
Copied!
Copied!

All versions