Google Maps

Vediamo come aggiungere una mappa di Google con marker prefissati a determinati indirizzi, inseriti in un array di variabili javascript(facilmente iniettabili nella pagina con un Literal):

 

var bounds = new GLatLngBounds();
 
function loadGMap() 
{
 if (GBrowserIsCompatible())
 {
  window.map = new GMap2(document.getElementById("mappp"));
  map.addControl(new GSmallMapControl());
  map.addControl(new GMapTypeControl());
  map.enableScrollWheelZoom();
  if (window.ARRAYVARIABILE) 
  { 
    for (var i = 0; i < ARRAYVARIABILE.length; i++)
    {
       addMarker(map, ARRAYVARIABILE[i]);
    }
  }
 }
}
 
 
function addMarker(map, variabile)
{
  var geocoder = new GClientGeocoder();
  if (geocoder)
  {
    geocoder.getLatLng
    (
      variabile.address,
      function(point)
      {
        if (!point) 
        {
          /*alert(address + "" not found "");*/
        }
        else 
        {
          map.setCenter(point, 10);
          // Crea un marker 
          var baseIcon = new GIcon();
          baseIcon.image = "img/xxx.png";
          baseIcon.shadow = "img/shadow-pv.png";
          baseIcon.iconSize = new GSize(52, 61);
          baseIcon.shadowSize = new GSize(49, 32); 
          baseIcon.iconAnchor = new GPoint(9, 32);
          baseIcon.infoWindowAnchor = new GPoint(9, 2);
          baseIcon.infoShadowAnchor = new GPoint(18, 25);
          var marker = new GMarker(point, baseIcon);
          bounds.extend(point);
          map.setZoom(map.getBoundsZoomLevel(bounds)-1);
          map.setCenter(bounds.getCenter());
          map.addOverlay(marker);
          GEvent.addListener
          (marker, 
           "click", 
           function() 
           {
             myTesto = "<span style='color: black;'>prova</span>";
             marker.openInfoWindowHtml(myTesto);
           }
          );
        }
      }
    );
  }
}
 
function winOpen(url)
{
  window.open(url, "_blank","height=100, width=200"); 
}
 
function loadGoogleMap()
{
  window.onunload = GUnload; 
  window.onload = loadGMap;
}
Technorati tags: ,

Print | posted @ domenica 15 giugno 2008 13:58

Comments have been closed on this topic.