SlideShare a Scribd company logo
1 of 15
ADDING A GOOGLE MAP
TO YOUR WEBSITE
By

Rajeev Ranjan


Adding a Google Map to your web page is very easy, once
you've been shown how! That's what we're going to do in
this lesson - we'll go over each step of creating a basic
Google Map using the JavaScript API.
WHAT YOU'LL NEED






You don't need much to create a Google Maps API
webpage:
A text editor. Windows machines generally include
Notepad; Mac OS X comes with TextEdit; Linux machines
come with a variety of applications, including gedit, vim, or
KWrite.
A web browser. We heart Google Chrome, but there are
many web browsers available for various platforms:
Firefox, Safari, and Internet Explorer are some of the bestknown options.
TRY IT OUT





The basic HTML page:Because everything on the web is made up of HTML, we'll
start there. The following code creates the simplest of web
pages:

None of this is specific to Google Maps - it's the basis for
any HTML page. Open your text editor and add this code,
then save the file to your desktop as google-maps.html (or
any other filename that ends with .html).


Your Google Map requires a page element in which to
appear; add a div tag to the body with an id attribute of
map canvas. This creates a container that we'll reference
later in the lesson.


Set the width and height of the div element using CSS. By
default, a div has a height of 0, meaning that any map you place
inside it won't be visible. Use a style tag in the head to set the
map to any size; in this case 500 pixels wide and 400 pixels high.





Load the HTML file in a web browser by dragging it from
your desktop into the address bar of your browser. You'll
notice that nothing is displayed - there's nothing in the div
yet. If you'd like to see the div on your page, add a
background-color CSS declaration to your existing <style>
tag:

Reloading the page will display a grey box; that's your div.
To bring forth a map, you must add two pieces of
JavaScript to your page. The first loads the Google Maps
JavaScript API; the second creates and configures the map.
LOADING THE API




Load the Google Maps API by adding a <script> tag to the <head>
section of your HTML. This script downloads the code required to
display maps on your page.

Notice that the URL contains a sensor parameter, which is set to false.
This example does not use any GPS device or sensor to detect the user's
location; if you're using any sort of geolocation in your application, this
must be changed to true
CREATE AND CONFIGURE THE MAP




The final piece of code is the JavaScript that creates the
map. The code contains a function to run once the page has
loaded. In this example, and all of the examples in the
Maps API documentation, this function is named initialize.

Add this code immediately after the <script> tag you
created in the last step.
THE GOOGLE.MAPS.MAP OBJECT






The first thing the initialize function needs to do is create a
new Google Maps object:

The Map object constructor takes two arguments:






center is a Google Maps LatLng object that tells the the API
where to center the map.
zoom is a number between 0 (farthest) and 22 that sets the
zoom level of the map.
mapTypeId is used to specify what type of map to use. Your
choices are ROADMAP, SATELLITE, HYBRID, or TERRAIN.
EXECUTING THE JAVASCRIPT FUNCTION


Add an event listener to the window object that will call the
initialize function once the page has loaded. Calling initialize
before the page has finished loading will cause problems,
since the div it's looking for may not have been created yet;
this function waits until the HTML elements on the page
have been created before calling initialize.
THE FINISHED CODE


This is the final code you've put together in this
lesson. It:



Creates a div, and gives it a size.



Loads the Google Maps JavaScript API v3.



Creates and displays a Google Map in the div.



Final Full code is in next slide….
Code to Add Google Map to Websites
Code to Add Google Map to Websites

More Related Content

What's hot

Minko - Windows App Meetup Nov. 2013
Minko - Windows App Meetup Nov. 2013Minko - Windows App Meetup Nov. 2013
Minko - Windows App Meetup Nov. 2013
Minko3D
 

What's hot (20)

AngularJS RTP Slides - Angular 2 Demo #ngtattoo with Angular CLI, Newest New ...
AngularJS RTP Slides - Angular 2 Demo #ngtattoo with Angular CLI, Newest New ...AngularJS RTP Slides - Angular 2 Demo #ngtattoo with Angular CLI, Newest New ...
AngularJS RTP Slides - Angular 2 Demo #ngtattoo with Angular CLI, Newest New ...
 
Angular2 + Ng-Lightning + Lightning Design System = Great Apps
Angular2 + Ng-Lightning + Lightning Design System = Great AppsAngular2 + Ng-Lightning + Lightning Design System = Great Apps
Angular2 + Ng-Lightning + Lightning Design System = Great Apps
 
Angular2 + New Firebase in Action
Angular2 + New Firebase in ActionAngular2 + New Firebase in Action
Angular2 + New Firebase in Action
 
Vue.js Component Tools
Vue.js Component ToolsVue.js Component Tools
Vue.js Component Tools
 
Build your first android mobile app
Build your first android mobile appBuild your first android mobile app
Build your first android mobile app
 
30 days GCP GDSC info session
30 days GCP GDSC info session30 days GCP GDSC info session
30 days GCP GDSC info session
 
Creating BananaJS with Angular 2, Angular CLI, and Material Design
Creating BananaJS with Angular 2, Angular CLI, and Material DesignCreating BananaJS with Angular 2, Angular CLI, and Material Design
Creating BananaJS with Angular 2, Angular CLI, and Material Design
 
Réaliser un jeu cross plateformes avec WebGL et babylon.js
Réaliser un jeu cross plateformes avec WebGL et babylon.jsRéaliser un jeu cross plateformes avec WebGL et babylon.js
Réaliser un jeu cross plateformes avec WebGL et babylon.js
 
Make your animations perform well - Anna Migas - Codemotion Rome 2017
Make your animations perform well - Anna Migas - Codemotion Rome 2017Make your animations perform well - Anna Migas - Codemotion Rome 2017
Make your animations perform well - Anna Migas - Codemotion Rome 2017
 
Minko - Windows App Meetup Nov. 2013
Minko - Windows App Meetup Nov. 2013Minko - Windows App Meetup Nov. 2013
Minko - Windows App Meetup Nov. 2013
 
Android App Development 20150409
Android App Development 20150409Android App Development 20150409
Android App Development 20150409
 
GAS Session
GAS SessionGAS Session
GAS Session
 
Google App Engine
Google App EngineGoogle App Engine
Google App Engine
 
App script
App scriptApp script
App script
 
Optimizing and Deploying Angular
Optimizing and Deploying AngularOptimizing and Deploying Angular
Optimizing and Deploying Angular
 
Migrating your Web app to Virtual Reality
Migrating your Web app to Virtual RealityMigrating your Web app to Virtual Reality
Migrating your Web app to Virtual Reality
 
Mobile backends with Google Cloud Platform (MBLTDev'14)
Mobile backends with Google Cloud Platform (MBLTDev'14)Mobile backends with Google Cloud Platform (MBLTDev'14)
Mobile backends with Google Cloud Platform (MBLTDev'14)
 
Web Os Hands On
Web Os Hands OnWeb Os Hands On
Web Os Hands On
 
Application Craft Tutorial for Google Map
Application Craft Tutorial for Google MapApplication Craft Tutorial for Google Map
Application Craft Tutorial for Google Map
 
Real-time image sharing
Real-time image sharingReal-time image sharing
Real-time image sharing
 

Viewers also liked

Mobile Development Architecture Ppt with Slides, Book Notes on using Web Silv...
Mobile Development Architecture Ppt with Slides, Book Notes on using Web Silv...Mobile Development Architecture Ppt with Slides, Book Notes on using Web Silv...
Mobile Development Architecture Ppt with Slides, Book Notes on using Web Silv...
Bala Subra
 
Android MapView and MapActivity
Android MapView and MapActivityAndroid MapView and MapActivity
Android MapView and MapActivity
Ahsanul Karim
 
Presentation on Android application
Presentation on Android applicationPresentation on Android application
Presentation on Android application
Atibur Rahman
 

Viewers also liked (20)

Um residencial com plantas espaçosas, acabamento Vip e localização nobre.
Um residencial com plantas espaçosas, acabamento Vip e localização nobre.Um residencial com plantas espaçosas, acabamento Vip e localização nobre.
Um residencial com plantas espaçosas, acabamento Vip e localização nobre.
 
Actitud de las autoridades educativas privadas en el uso de plataforma web
Actitud de las autoridades educativas privadas en el uso de plataforma webActitud de las autoridades educativas privadas en el uso de plataforma web
Actitud de las autoridades educativas privadas en el uso de plataforma web
 
Android Application on Location sharing and message sender
Android Application on Location sharing and message senderAndroid Application on Location sharing and message sender
Android Application on Location sharing and message sender
 
Secure my ng-app
Secure my ng-appSecure my ng-app
Secure my ng-app
 
Must Know Google Map Features for your Web application
Must Know Google Map Features  for your Web applicationMust Know Google Map Features  for your Web application
Must Know Google Map Features for your Web application
 
Google Map API
Google Map APIGoogle Map API
Google Map API
 
CATALÀ - Llinatges mapa activitat
CATALÀ  - Llinatges mapa activitatCATALÀ  - Llinatges mapa activitat
CATALÀ - Llinatges mapa activitat
 
Client-Server
Client-ServerClient-Server
Client-Server
 
Mobile Development Architecture Ppt with Slides, Book Notes on using Web Silv...
Mobile Development Architecture Ppt with Slides, Book Notes on using Web Silv...Mobile Development Architecture Ppt with Slides, Book Notes on using Web Silv...
Mobile Development Architecture Ppt with Slides, Book Notes on using Web Silv...
 
Android MapView and MapActivity
Android MapView and MapActivityAndroid MapView and MapActivity
Android MapView and MapActivity
 
Location sharing and automatic message sender Android Application
Location sharing and automatic message sender Android ApplicationLocation sharing and automatic message sender Android Application
Location sharing and automatic message sender Android Application
 
Los derechos de la mujer dominicana
Los derechos de la mujer dominicanaLos derechos de la mujer dominicana
Los derechos de la mujer dominicana
 
Google Maps API for Android
Google Maps API for AndroidGoogle Maps API for Android
Google Maps API for Android
 
Vehicle tracking system using gps and google map
Vehicle tracking system using gps and google mapVehicle tracking system using gps and google map
Vehicle tracking system using gps and google map
 
Android ppt
Android pptAndroid ppt
Android ppt
 
Final year project presentation in android application
Final year project presentation in android applicationFinal year project presentation in android application
Final year project presentation in android application
 
Presentation on Android application
Presentation on Android applicationPresentation on Android application
Presentation on Android application
 
Android Project Presentation
Android Project PresentationAndroid Project Presentation
Android Project Presentation
 
Mobile Application Development
Mobile Application DevelopmentMobile Application Development
Mobile Application Development
 
Android ppt
Android pptAndroid ppt
Android ppt
 

Similar to Code to Add Google Map to Websites

Build Android App using GCE & GAE
Build Android App using GCE & GAEBuild Android App using GCE & GAE
Build Android App using GCE & GAE
Love Sharma
 
Introduction to App Engine Development
Introduction to App Engine DevelopmentIntroduction to App Engine Development
Introduction to App Engine Development
Ron Reiter
 
Android howto hellowidget
Android howto hellowidgetAndroid howto hellowidget
Android howto hellowidget
Hiron Das
 

Similar to Code to Add Google Map to Websites (20)

Progressive Web Application by Citytech
Progressive Web Application by CitytechProgressive Web Application by Citytech
Progressive Web Application by Citytech
 
Link your HTML Form to Google Sheet in just 3 Steps.pdf
Link your HTML Form to Google Sheet in just 3 Steps.pdfLink your HTML Form to Google Sheet in just 3 Steps.pdf
Link your HTML Form to Google Sheet in just 3 Steps.pdf
 
Google Apps Script: Accessing G Suite & other Google services with JavaScript
Google Apps Script: Accessing G Suite & other Google services with JavaScriptGoogle Apps Script: Accessing G Suite & other Google services with JavaScript
Google Apps Script: Accessing G Suite & other Google services with JavaScript
 
Intro To Google Maps
Intro To Google MapsIntro To Google Maps
Intro To Google Maps
 
Android
AndroidAndroid
Android
 
ArcGIS API for Javascript Tutorial
ArcGIS API for Javascript TutorialArcGIS API for Javascript Tutorial
ArcGIS API for Javascript Tutorial
 
Google Apps Script for Beginners- Amazing Things with Code
Google Apps Script for Beginners- Amazing Things with CodeGoogle Apps Script for Beginners- Amazing Things with Code
Google Apps Script for Beginners- Amazing Things with Code
 
Everything about flutter web development
Everything about flutter web developmentEverything about flutter web development
Everything about flutter web development
 
What is Objective-j
What is Objective-jWhat is Objective-j
What is Objective-j
 
How to build and deploy app on Replit
How to build and deploy app on ReplitHow to build and deploy app on Replit
How to build and deploy app on Replit
 
Build Android App using GCE & GAE
Build Android App using GCE & GAEBuild Android App using GCE & GAE
Build Android App using GCE & GAE
 
Google Maps API 101
Google Maps API 101Google Maps API 101
Google Maps API 101
 
Ez Community Gandbox.fr
Ez Community Gandbox.frEz Community Gandbox.fr
Ez Community Gandbox.fr
 
@Ionic native/google-maps
@Ionic native/google-maps@Ionic native/google-maps
@Ionic native/google-maps
 
Integrate Google Map SDK in iOS App
Integrate Google Map SDK in iOS AppIntegrate Google Map SDK in iOS App
Integrate Google Map SDK in iOS App
 
IE9 for developers
IE9 for developersIE9 for developers
IE9 for developers
 
Introduction to App Engine Development
Introduction to App Engine DevelopmentIntroduction to App Engine Development
Introduction to App Engine Development
 
Android how to hellowidget
Android how to hellowidgetAndroid how to hellowidget
Android how to hellowidget
 
Android howto hellowidget
Android howto hellowidgetAndroid howto hellowidget
Android howto hellowidget
 
Location Based Services Without the Cocoa
Location Based Services Without the CocoaLocation Based Services Without the Cocoa
Location Based Services Without the Cocoa
 

More from Fortune Innovations Dublin

More from Fortune Innovations Dublin (6)

Sample SEO Audit Report
Sample SEO Audit ReportSample SEO Audit Report
Sample SEO Audit Report
 
On page optimization
On page optimizationOn page optimization
On page optimization
 
Off page optimization
Off page optimization Off page optimization
Off page optimization
 
Drupal theme development
Drupal theme developmentDrupal theme development
Drupal theme development
 
Seo Presentation
Seo PresentationSeo Presentation
Seo Presentation
 
Humming bird update ppt
Humming bird update pptHumming bird update ppt
Humming bird update ppt
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

Code to Add Google Map to Websites

  • 1. ADDING A GOOGLE MAP TO YOUR WEBSITE By Rajeev Ranjan
  • 2.  Adding a Google Map to your web page is very easy, once you've been shown how! That's what we're going to do in this lesson - we'll go over each step of creating a basic Google Map using the JavaScript API.
  • 3. WHAT YOU'LL NEED    You don't need much to create a Google Maps API webpage: A text editor. Windows machines generally include Notepad; Mac OS X comes with TextEdit; Linux machines come with a variety of applications, including gedit, vim, or KWrite. A web browser. We heart Google Chrome, but there are many web browsers available for various platforms: Firefox, Safari, and Internet Explorer are some of the bestknown options.
  • 4. TRY IT OUT    The basic HTML page:Because everything on the web is made up of HTML, we'll start there. The following code creates the simplest of web pages: None of this is specific to Google Maps - it's the basis for any HTML page. Open your text editor and add this code, then save the file to your desktop as google-maps.html (or any other filename that ends with .html).
  • 5.  Your Google Map requires a page element in which to appear; add a div tag to the body with an id attribute of map canvas. This creates a container that we'll reference later in the lesson.
  • 6.  Set the width and height of the div element using CSS. By default, a div has a height of 0, meaning that any map you place inside it won't be visible. Use a style tag in the head to set the map to any size; in this case 500 pixels wide and 400 pixels high.
  • 7.    Load the HTML file in a web browser by dragging it from your desktop into the address bar of your browser. You'll notice that nothing is displayed - there's nothing in the div yet. If you'd like to see the div on your page, add a background-color CSS declaration to your existing <style> tag: Reloading the page will display a grey box; that's your div. To bring forth a map, you must add two pieces of JavaScript to your page. The first loads the Google Maps JavaScript API; the second creates and configures the map.
  • 8. LOADING THE API   Load the Google Maps API by adding a <script> tag to the <head> section of your HTML. This script downloads the code required to display maps on your page. Notice that the URL contains a sensor parameter, which is set to false. This example does not use any GPS device or sensor to detect the user's location; if you're using any sort of geolocation in your application, this must be changed to true
  • 9. CREATE AND CONFIGURE THE MAP   The final piece of code is the JavaScript that creates the map. The code contains a function to run once the page has loaded. In this example, and all of the examples in the Maps API documentation, this function is named initialize. Add this code immediately after the <script> tag you created in the last step.
  • 10. THE GOOGLE.MAPS.MAP OBJECT    The first thing the initialize function needs to do is create a new Google Maps object: The Map object constructor takes two arguments:
  • 11.    center is a Google Maps LatLng object that tells the the API where to center the map. zoom is a number between 0 (farthest) and 22 that sets the zoom level of the map. mapTypeId is used to specify what type of map to use. Your choices are ROADMAP, SATELLITE, HYBRID, or TERRAIN.
  • 12. EXECUTING THE JAVASCRIPT FUNCTION  Add an event listener to the window object that will call the initialize function once the page has loaded. Calling initialize before the page has finished loading will cause problems, since the div it's looking for may not have been created yet; this function waits until the HTML elements on the page have been created before calling initialize.
  • 13. THE FINISHED CODE  This is the final code you've put together in this lesson. It:  Creates a div, and gives it a size.  Loads the Google Maps JavaScript API v3.  Creates and displays a Google Map in the div.  Final Full code is in next slide….