How to add google map to website with marker with Example

How to add google map to website with marker with Example

Hello friends, in this tutorial I will explain step by step with an example of how to add google map to website with a marker. This is a very important part of website development because everyone wants to embed Google Maps on their sites so that users or visitors can navigate to their desired locations by zooming on the map.

How to add google map to website with marker with Example

Before getting started with the example, make sure that you have the basic knowledge of HTML, CSS, and JavaScript.

Also read, Get user location from the browser using JavaScript and Geolocation API

Required steps to add Google map to website with marker

Step 1:- Create an HTML page as shown below

<!DOCTYPE html>
<html>
  <head>
    <title>Add Map</title>
    <link rel="stylesheet" type="text/css">
  </head>
  <body>
    <h3 align="center">My Google Map for New Delhi</h3>
    <!--The div element for the map -->
    <div id="map"></div>
  </body>
</html>

Understand the above code:-

  • Declare a div tag to display the area of the map on the web page.

Step 2:- Get an API key from Google Cloud Console

Step 3:- Design the map using CSS inside the style tag under the head section as shown below.

<style type="text/css">
      #map {
            height: 400px;
            /* The height is 400 pixels */
            width: 60%;
            /* The width is the width of the web page */
          }
</style>

In the CSS part, I have set the size of the map using height and width

Step 4:- Add a map with a marker using javascript.

<!-- Async script executes immediately and must be after any DOM elements used in callback. -->
    <script src="https://maps.googleapis.com/maps/api/js?key=your api key&callback=initMap&v=weekly"
      async
    ></script>
    <script type="text/javascript">
      // Initialize and add the map
          function initMap() {
            // The location of delhi
            const delhi = { lat: 28.644800, lng: 77.216721 };
            // The map, centered at delhi
            const map = new google.maps.Map(document.getElementById("map"), {
              zoom: 4,
              center: delhi,
            });
            // The marker, positioned at delhi
            const marker = new google.maps.Marker({
              position: delhi,
              map: map,
            });
          }
    </script>

Understand the code:-

  • First of all, we will load the maps javascript API using the script tag as shown below. The callback parameter will execute the initMap() function that will add a map to your page later.
  • The initMap() function initializes and adds the google map to your web page for your desired location when the web page loads.
  • The Below code creates a new Google map object and sets the center and zoom property for the location you want to display. You have to set the latitude and longitude of your location. The more you set the zoom property, you can view the earth’s locations at higher resolutions.
// The location of Delhi
            const delhi = { lat: 28.644800, lng: 77.216721 };
            // The map, centered at Delhi
            const map = new google.maps.Map(document.getElementById("map"), {
              zoom: 4,
              center: delhi,
            });
  • The below code will display the marker for your location on the Google map at the centered position.
// The marker, positioned at delhi
            const marker = new google.maps.Marker({
              position: delhi,
              map: map,
     });

Complete Code:-

<!DOCTYPE html>
<html>
  <head>
    <title>Add Map</title>

    <link rel="stylesheet" type="text/css">
    <style type="text/css">
      #map {
            height: 400px;
            /* The height is 400 pixels */
            width: 60%;
            /* The width is the width of the web page */
          }
    </style>
  </head>
  <body>
    <h3 align="center">My Google Map for New Delhi</h3>
    <!--The div element for the map -->
    <div id="map"></div>

    <!-- Async script executes immediately and must be after any DOM elements used in callback. -->
    <script
      src="https://maps.googleapis.com/maps/api/js?key=your api key&callback=initMap&v=weekly"
      async
    ></script>
    <script type="text/javascript">
      // Initialize and add the map
          function initMap() {
            // The location of Delhi
            const delhi = { lat: 28.644800, lng: 77.216721 };
            // The map, centered at Delhi
            const map = new google.maps.Map(document.getElementById("map"), {
              zoom: 4,
              center: delhi,
            });
            // The marker, positioned at Delhi
            const marker = new google.maps.Marker({
              position: delhi,
              map: map,
            });
          }
    </script>
  </body>
</html>

Google places autocomplete example using maps JavaScript API

Conclusion:- I hope this tutorial will help you to understand the overview of positioning the Google map with a marker. If there is any doubt then please leave a comment below

Leave a Comment

KUPU178

KUPU178

KUPU178

hoki311

hoki311

hoki311

hoki311

hoki311

RATU311

KUPU178

HOKI311

THOR311

THOR311

login hoki311

daftar hoki311

hoki 311

link hoki311

hoki311

RATU311

hoki311

hoki311

hoki311

hoki311

KUPU178

thor311

thor311

thor311

ceri188

ceri188

KUPU178

ceri188

ceri188

link ceri188

KUPU178

KUPU178

KUPU178

kupu178

ceri188

ceri188

ceri188

ceri188

ceri188

THOR311

ceri188

games online ceri188

link login ceri188

ceri188

thor311

RATU311

RATU311

RATU311

sbobet88

sbobet

parlay

mix parlay

judi bola online

thor311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

THOR311

THOR311

THOR311

THOR311

thor311 RTP

thor311

slot gacor

kupu178

slot mahjong

ceri188

sabung ayam

ratu311

THOR311

THOR311

THOR311

thor311 aplikasi

ratu311 sabung ayam

slot gacor

RATU311

ceri188

ceri188

ceri188

ceri188

KUPU178

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

ceri188

ceri188

ceri188 alternatif

ceri188

link ceri188

ceri188

RATU311

THOR311

THOR311

THOR311

RATU311

RATU311

RATU311

Togel Online

KUPU178

Situs Togel

KUPU178

ceri188

ceri188

KUPU178

KUPU178

ceri188

ceri188

ratu311

ceri188

ceri188

ratu311

KUPU178

THOR311

ceri188

ceri188

THOR311

THOR311

RATU311

thor311 tajen bali

thor311 alternatif

situs toto4d

thor311 toto4d

thor311 akses

ceri188

daftar ceri188

cery188

ceri188

slot gacor

kupu 178

kupu178

ceri1888

ceri188

slot online

hoki311

togel online

ceri188

ding dong

ratu311

slot gacor

kupu178

live casino

kupu178

mix parlay

ceri188

judi bola online

thor311 slot

THOR311

RATU311

KUPU178

THOR311

ceri188

ratu311

slot online

hoki311

kupu178

togel online

kupu178

slot gacor

ceri188

judi bola online

ceri188

ratu311

kupu178

RATU311

RATU311

live casino roullete

ceri188

slot pg soft

kupu178

KUPU178

THOR311

RATU311

KUPU178

THOR311

THOR311

thor311 domino qq

thor311 akses

thor dingdong

ceri188

ceri188

kupu178

kupu178

togel

kupu178

mix parlay

ceri188

slot online

kupu178

THOR311

THOR311

KUPU178

kupu178

hoki311

togel online

kupu178

ceri188

ceri188

www.vrcorporate.in

phbalance.vn

togel hongkong

kupu178

slot gacor

kupu178

kupu178

ceri188

kupu178

KUPU178

RATU311

slot online

kupu178

THOR311

KUPU178

slot mahjong ways

hoki311

slot gacor

ceri188

kupu178

Casino Baccarat Online

kupu178

kupu178

ceri188

toto macau

KUPU178

Slot Gacor

KUPU178

RATU311

Mahjong ways

KUPU178

KUPU178

KUPU178

RATU311

RATU311

Toto Togel

KUPU178

CERI188

Slot Sweet Bonanza 2500

KUPU178

RATU311

KUPU178 X SLOT777

judi bola online

THOR311

KUPU178 SLOT TERPERCAYA

KUPU178 TOGEL

TOTO 4D MACAU

KUPU178

THOR311

HOKI311

KUPU178

Slot Mahjong Ways

KUPU178

CERI188

Slot Online Resmi

KUPU178

RATU311 SLOT ONLINE

KUPU178

KUPU178: Link Akses Resmi

KUPU178: Strategi Menang Di Game Live Casino

KUPU178

KUPU178: Minimal 200 Rupiah

THOR311

THOR311

THOR311

THOR311

THOR311

KUPU178

Slot Thailand

CERI188

CERI188

THOR311 RTP

RATU311

CERI188

KUPU178 TOTO SLOT

CERI188 TOTO Singapore

THOR311

CERI188

RATU311: Alternatif karnpuracollege

Thor311 Terbaru

THOR311 MAHJONG

RATU311: BONUS SABUNG AYAM

CERI188: Masuk Akun Slot Super Cepat

THOR311

HOKI311

HOKI311

RATU311

HOKI311

KUPU178

RATU311

RATU311

THOR311

CERI188

CERI188

RATU311

RATU311

RATU311

Game Thor311

HOKI311

HOKI311

RATU311

HOKI311

HOKI311

RATU311 NONTON BOLA

HOKI311 Link QRIS EWALLET

RATU311

HOKI311 Link Apk Resmi

RATU311 judi bola

KUPU178

HOKI311

RATU311

THOR311

HOKI311

KUPU178

KUPU178

RATU311

RATU311

KUPU178

THOR311

KUPU178

RATU311

THOR311