    var map;
    var gdir;
    var geocoder = null;
    var addressMarker;

    function initialize() {
		if(document.getElementById('local_gmap')){
		  if (GBrowserIsCompatible()) {      
			map = new GMap2(document.getElementById("map_canvas"));
			gdir = new GDirections(map, document.getElementById("directions"));
			geocoder = new GClientGeocoder();
			GEvent.addListener(gdir, "load", onGDirectionsLoad);
			GEvent.addListener(gdir, "error", handleErrors);
			inicia_mapa();
		  }
	  	}
	}
    
	// Ícone
	var marca = new GIcon();
		marca.image = "images/gmaps.png";
		marca.shadow = "images/gmaps_shadow.png";
		marca.iconSize = new GSize(36, 34);
		marca.shadowSize = new GSize(54, 34);
		marca.iconAnchor = new GPoint(10, 0);
		marca.infoWindowAnchor = new GPoint(20, 0);
		marca.infoShadowAnchor = new GPoint(18, 25);
		marca.transparent = "images/markertransparent.png";
		marca.printImage = "images/gmaps.png";
		marca.mozPrintImage = "images/gmaps.png";

	
	function inicia_mapa(){
		var local = document.getElementById('local_gmap').value;
		var html = document.getElementById('html_gmap').value;
		geocoder.getLatLng(
			local,
			function(point) {
			  if (!point) {
				mensagem("O endereço ("+local+") não foi encontrado.");
			  } else {
				map.setCenter(point, 17);
				var marker = new GMarker(point,marca);
				map.addOverlay(marker);
				marker.openInfoWindowHtml(html);
				// adicione aqui os controles do google
				map.addControl(new GSmallMapControl());
			  }
			}
		);
	}

    function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     mensagem("O endereço informado não foi encontrado, talvez ele ainda não tenha sido mapeado pelo Google Maps.");
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     mensagem("As coordenadas informadas não foram encontradas, certifique-se de ter escrito no padrão.");

	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     mensagem("The HTTP parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     mensagem("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     mensagem("O caminho solicitado não pode ser construído, verifique se informou corretamente seu endereço.");

	   else mensagem("Erro desconhecido.");
	}

	function onGDirectionsLoad(){
	}