Google Maps | Introduction

Google Maps is a web mapping service that is free by Google. This service provides various types of geographical information. With the help of google map, searching places and direction can be done. Also, we can get the traffic information of a specific area or view street-level images of cities.

Google Maps has a JavaScript API. This API is used to customize the map which displays the information.

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        Google Maps | Introduction
    </title>
      
    <!-- Add Google map API source -->
    <script src=
    </script>
  
    <script>
        function GFG() {
  
            var CustomOp = {
                center: new google.maps.LatLng(
                        28.502212, 77.405603),
                zoom: 17,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
  
            // Map object
            var map = new google.maps.Map(
                document.getElementById("DivID"),
                CustomOp
            );
        }
    </script>
</head>
  
<!-- Function that execute when page load -->
<body onload="GFG()">
    <center>
        <h1 style="color:green">
            GeeksforGeeks
        </h1>
          
        <h3>Google Maps</h3>
          
        <!-- Basic Container -->
        <div id="DivID" 
            style="width:400px; height:300px;">
        </div>
    </center>
</body>
  
</html>

chevron_right


Output:

Exaplaination:



  • In the above example, we will use Google API to load google map.
    <script src = "https://maps.googleapis.com/maps/api/js"></script>

    Following are the steps required to get an API key:

  • To custmize the maps:
    var CustomOp = {
        center:new google.maps.LatLng(28.502212, 77.405603), 
        zoom:17, 
        mapTypeId:google.maps.MapTypeId.ROADMAP
    };

    In this case, CustomOp is an object that contains 3 options, centre, zoom, and maptypeid.

    • centre: This property is used to set the specific point in maps.
    • zoom: This property is used to specify the zoom level on a specific point.
    • maptypeid: This property is used to specify the type of map. (ROADMAP, SATELLITE, HYBRID, TERRAIN)
  • To create a map object we will use the following code:

    var map = new google.maps.Map(document.getElementById("DivID"), CustomOp);

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.