JavaScript - Display Google Map Data

In this tutorial we will create a Display Google Map Data using Javascript. JavaScript is a scripting or programming language that allows you to implement complex things on web pages. It is widely used in designing a stunning website. It is an interpreted programming language that has a capabilities of Object-Oriented. This code can be used as your calculator to any mathematical problem. So Let's do the coding...

Getting Started:

This is the link for the jquery that i used in this tutorial https://jquery.com/. And, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.

Creating The Interface

This is where we will create a simple form for our application. To create the forms simply copy and write it into you text editor, then save it as index.html.
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.         <head>
  4.                 <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
  5.                 <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
  6.         </head>
  7.         <nav class="navbar navbar-default">
  8.                 <div class="container-fluid">
  9.                         <a href="https://sourcecodester.com" class="navbar-brand">Sourcecodester</a>
  10.                 </div>
  11.         </nav>
  12.         <div class="col-md-3"></div>
  13.         <div class="col-md-6 well">
  14.                 <h3 class="text-primary">Javascript - Display Google Map Data</h3>
  15.                 <hr style="border-top:1px dotted #ccc;"/>
  16.                 <button class="btn btn-primary" id="get_map"><span class="glyphicon glyphicon-location"></span> Load Map</button>
  17.                 <div id="map" style="height:300px; display:none;"></div>
  18.         </div>
  19.         <script src="js/jquery-3.2.1.min.js"></script>
  20.         <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap" async defer></script>  
  21.         <script>
  22.                 var map;
  23.                 function initMap() {
  24.                         map = new google.maps.Map(document.getElementById('map'), {
  25.                                 center: {lat: 9.5162, lng: 123.158},
  26.                                 zoom: 8
  27.                         });
  28.                 }
  29.         </script>
  30.         <script src="js/script.js"></script>
  31. </body>
  32. </html>

Getting the Google Map API key

In order to get your api key, first you need to login your google accounts. Then visit this site https://console.developers.google.com/apis/dashboard. After that create a project here. tut1 Then, after the project is created go to Credentials and generate your key here. tut2

Displaying the Map

This code contains the function for displaying of the application. This code will display the google map when clicked. To do this just kindly copy and write these block of codes inside the text editor, then save it as script.js.
  1. $(document).ready(function(){
  2.         $('#get_map').on('click', function(){
  3.                 $('#map').show();
  4.         });
  5. });
There you have it we successfully created Display Google Map Data using Javascript. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!!

Add new comment