To create a Basic Google Map follow the procedure below.
Load Google Maps API using JavaScript tag as shown below.
[c]<script src=<a href="http://maps.googleapis.com/maps/api/js">http://maps.googleapis.com/maps/api/js</a>></script>[/c]
<div>
tag used to create Map Container as shown below.
[c]<div id=”googleMap” style=”width:600px;height:480px:”></div>[/c]
Center, MapTypeId, Zoom are the main options to be set before initializing.
Center - Center used to display the center of the map, which depends on the given LatLng object.
Pass the
latitude and
longitudes to the constructor of the required location.
MapTypeId - Google Maps API contains four types of Maps they are.
- MapTypeId.ROADMAP - Default Map type which displays road map view.
- MapTypeId.HYBRID - Both the mixture of normal and satellite views are displayed.
- MapTypeId.TERRAIN - Map based on terrain information get displayed using this map type.
- MapTypeId.SATELLITE - Earth Satellite images are displayed.
Zoom - Used to set the zoom level of a map.
[c]
function initialize() {
var mapProp = {
center: new google.maps.LatLng( 17.3700, 78.4800 ),
zoom: 8
mapTypeId: google.maps.MapTypeId.ROADMAP
};
[/c]
The below code create a Map Object with the Id “googleMap”, by passing the parameters (mapProp).
[c]Var map=new google.maps.Map(document.getElementById(“googleMap”), mapProp);[/c]
Adding the DOM listener will execute the initialize () function on loaded window.
[c]Google.maps.event.addDomListener(window, ‘load’ , initialize);[/c]