Wednesday, July 3, 2024
HomeLanguagesJavascriptGoogle Maps Markers

Google Maps Markers

The process of drawing objects on the map and bind them to a desired latitude and longitude is called overlays.
Various overlays Google Maps provides.

  • Markers
  • Polylines
  • Polygons
  • Circle and rectangle
  • Info window
  • Symbols

Google Maps markers are provided to mark a single location on the map. These markers use a standard symbol that is customizable.

Syntax:

var marker = new google.maps.Marker({
   position: new google.maps.LatLng(19.373341, 78.662109),
   map: map,
});  

Example 1:




<!DOCTYPE html>
<html>
    <head>
        <!-- Loading map API -->
        <script src=
           "https://maps.googleapis.com/maps/api/js">
      </script>
  
        <script>
            function GFG() {
                var CustomOp = {
                    center: 
               new google.maps.LatLng(28.502212, 77.405603),
                    zoom: 17,
                };
  
                // Map object
                var map = 
new google.maps.Map(document.getElementById("DivID"), CustomOp);
                var marker = new google.maps.Marker({
                    position: 
                  new google.maps.LatLng(28.502211, 77.405512),
                    map: map,
                });
            }
        </script>
    </head>
    <!-- load map -->
    <body onload="GFG()">
        <center>
            <h1 style="color: green;">
              neveropen</h1>
            <h3>Google Maps</h3>
            <!-- Basic Container -->
            <div id="DivID" 
                 style="width: 400px;
                        height: 300px;">
          </div>
        </center>
    </body>
</html>


Output:

Example 2: To customize the marker.




<!DOCTYPE html>
<html>
    <head>
        <!-- Loading map API -->
        <script src=
           "https://maps.googleapis.com/maps/api/js">
      </script>
  
        <script>
            function GFG() {
                var CustomOp = {
                    center: 
               new google.maps.LatLng(28.502212, 77.405603),
                    zoom: 17,
                };
  
                // Map object
                var map = 
new google.maps.Map(document.getElementById("DivID"), CustomOp);
                var marker = new google.maps.Marker({
                    position: 
                  new google.maps.LatLng(28.502211, 77.405512),
                    map: map,
                  animation:google.maps.Animation.BOUNCE 
                });
            }
        </script>
    </head>
    <!-- load map -->
    <body onload="GFG()">
        <center>
            <h1 style="color: green;">
              neveropen</h1>
            <h3>Google Maps</h3>
            <!-- Basic Container -->
            <div id="DivID" 
                 style="width: 400px;
                        height: 300px;">
          </div>
        </center>
    </body>
</html>


Output:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Shaida Kate Naidoo
am passionate about learning the latest technologies available to developers in either a Front End or Back End capacity. I enjoy creating applications that are well designed and responsive, in addition to being user friendly. I thrive in fast paced environments. With a diverse educational and work experience background, I excel at collaborating with teams both local and international. A versatile developer with interests in Software Development and Software Engineering. I consider myself to be adaptable and a self motivated learner. I am interested in new programming technologies, and continuous self improvement.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments