Computer Magic Logo
Display a map

Thursday, December 1, 2016

Published by Aristotelis Pitaridis

The following script can be used in order to display a google map on a web page. We have to replace the YOUR_API_KEY with a valid google maps API key.

<!DOCTYPE html>
<html>
<head>
    <style>
        #map {
            height: 400px;
            width: 600px;
        }
    </style>
</head>
<body>
    <h3>My Google Maps Demo</h3>
    <div id="map"></div>
    <script>
        function initMap() {
            var location = { lat: 35.339186, lng: 25.1315903 };
            var map = new google.maps.Map(document.getElementById('map'), {
                zoom: 12,
                center: location
            });
        }
    </script>
    <script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"></script>
</body>
</html>