Integrating Google Maps 3 in website
Google Maps had a new version announced on Google I/O 2013. The maps is live now. For developers using the previous version. That was pretty easy to integrate the maps in to the website because there was a button to get the integration code which was based on iframe. But version 3, has a new set of API, and integration code is to be written by self. And for this we need to know the latitude and longitude of the address we want to integrate in website.
Integrating Google Maps 3 has a few steps to do:
1. Include the maps library:
<script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>2. Make an area to display the map
<div id="map_canvas"></div>3. Display the map in the area with id map_canvas.
<script>Some points to node are:
function initialize() {
var map_canvas = document.getElementById('map_canvas');
var map_options = {
center: new google.maps.LatLng(27.7, 85.33333330000005),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(map_canvas, map_options)
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
1. use <!doctypt >
2. Change the latitude and longitude in this line below where the format is (latitude,longitude)
center: new google.maps.LatLng(27.7, 85.33333330000005),If you don't know the latitude and longitude of the place you want to use in Google maps integration then check this post: Getting Latitude and Longitude from Google Maps.
The full working code snippet to integrate Google Maps 3 is as follows:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Google Maps 3 Integration </title>
<style>
#map_canvas {
width: 600px;
height: 400px;
}
</style>
<script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script>
function initialize() {
var map_canvas = document.getElementById('map_canvas');
var map_options = {
center: new google.maps.LatLng(27.7, 85.33333330000005),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(map_canvas, map_options)
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map_canvas"></div>
</body>
</html>
Comments
Post a Comment