JS as follows:
(function () {
???? Window.onload = function () {
???????? Creating an object literal containing the properties
???????? We want to pass to the map
???????? var options = {
???????????? Zoom:3,
???????????? Center:new Google.maps.LatLng (37.09,-95.71),
???????????? MapTypeId:google.maps.MapTypeId.ROADMAP
????????};
???????? Creating the Map
???????? var map = new Google.maps.Map (document.getElementById (' map '), options);
???????? Creating An array that would contain the coordinates
???????? For New York, San Francisco, and Seattle
???????? var places = [];
???????? Adding a Latlng object for each city
???????? Places.push (New Google.maps.LatLng (40.756,-73.986));
???????? Places.push (New Google.maps.LatLng (37.775,-122.419));
???????? Places.push (New Google.maps.LatLng (47.620,-122.347));
???????? Looping through the Places array
???????? for (var i = 0; i < places.length; i++) {
???????????? Adding the marker as usual
???????????? var marker = new Google.maps.Marker ({
???????????????? Position:places[i],
???????????????? Map:map,
???????????????? Title: ' Place number ' + I
????????????});
???????????? Wrapping the event listener inside an anonymous function
???????????? That we immediately invoke and passes the variable i to.
???????????? (Function (i, marker) {
???????????????? Creating the event listener. It now have access to the values of
???????????????? I and marker as they were during its creation
???????????????? Google.maps.event.addListener (marker, ' click ', function () {
???????????????????? var Infowindow = new Google.maps.InfoWindow ({
???????????????????????? Content: ' Place number ' + I
????????????????????});
???????????????????? Infowindow.open (map, marker);
????????????????});
????????????}) (I, marker);
????????}
????}
})();
CSS as follows:
Body{
font-family< Span style= "COLOR: #38444b" >:verdana ,geneva , arial, helvetica,sans-serif;
Font-size:small;
Background:#fff;
}
#map{
Width:%;
Height:px;
Border:1pxsolid#000;
}
. info{
Width:+px;
}
?
HTML as follows:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" Content="text/html; Charset=utf-8 " />
<title>my first map</title>
<link type= "text/css" href=" Css/style.css " rel= "stylesheet" media=/>
<script Span style= "COLOR: #cb2d01" >type= "Text/javascript" src= "Http://maps.google.com/maps /api/js?sensor=false "></script >
<script type="Text/javascript" src="Js/map.js"></script>
</head>
<body>
<H1>my first map</H1>
<div id="Map"></div>
</body>
</html>
?
The effect is as follows:
Click on the label to display the description on Google Maps and keep it intact