    var map      = null;
    var geocoder = new GClientGeocoder();

    function showLatLng(lat, lng) {
        if (GBrowserIsCompatible()) {
            var map = new GMap2(document.getElementById("map"));
            GEvent.addListener(map, "moveend", function() {
              var center = map.getCenter();
            });
            map.addControl(new GSmallMapControl());
            map.addControl(new GMapTypeControl());
            var point = new GLatLng(lat, lng);
            var marker = new GMarker(point);
            map.setCenter(point, 15);
            map.setMapType(G_HYBRID_MAP);

            map.addOverlay(marker);

            var icon = new GIcon();
            icon.image = "http://www.google.com/mapfiles/marker.png";
            icon.shadow = "http://www.google.com/mapfiles/shadow50.png";
            icon.iconSize = new GSize(20, 34);
            icon.shadowSize = new GSize(37, 34);
            icon.iconAnchor = new GPoint(9, 34);
            icon.infoWindowAnchor = new GPoint(9, 2);
            icon.infoShadowAnchor = new GPoint(18, 25);

            map.addOverlay(new GMarker(point, icon));

            // bind a search control to the map, suppress result list
            map.addControl(new google.maps.LocalSearch(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,20)));
        }
    }

    function getCoords(address, latitud, longitud) {
        if (typeof(latitud) == 'undefined' || latitud == '') {
            latitud = 'latitud';
        }
        if (typeof(longitud) == 'undefined' || longitud == '') {
            longitud = 'longitud';
        }
        if (geocoder) {
            geocoder.getLatLng(
                address,
                function(point) {
                    if (!point) {
                        if ($(latitud) && $(longitud) && $(latitud).value == '' && $(longitud).value == '') {
                            alert('no se ha podido encontrar las coordenadas, especifiquelas manualmente');
                        }
                        return false;
                    } else {
                        if ($(latitud)) {
                            $(latitud).value = point.lat();
                        }
                        if ($(longitud)) {
                            $(longitud).value = point.lng();
                        }
                    }
                }
            );
        }
    }

    function showAddress(address) {
		if (GBrowserIsCompatible()) {
			map = new GMap2(document.getElementById("map"));
			if (geocoder) {
				geocoder.getLatLng(
					address,
					function(point) {
						if (!point) {
							document.getElementById("map").innerHTML = '<a href="http://maps.google.es/maps?f=q&amp;hl=es&amp;geocode=&amp;q='+address+'&amp;ie=UTF8&amp;iwloc=addr" target="_blank">No se ha encontrado mapa en google, pulse para buscar</a>';
							return;
						} else {
							GEvent.addListener(map, "moveend", function() {
								var center = map.getCenter();
							});
							map.addControl(new GSmallMapControl());
							map.addControl(new GMapTypeControl());
							map.setCenter(point, 15);
							map.setMapType(G_HYBRID_MAP);

							var icon = new GIcon();
							icon.image = "http://www.google.com/mapfiles/marker.png";
							icon.shadow = "http://www.google.com/mapfiles/shadow50.png";
							icon.iconSize = new GSize(20, 34);
							icon.shadowSize = new GSize(37, 34);
							icon.iconAnchor = new GPoint(9, 34);
							icon.infoWindowAnchor = new GPoint(9, 2);
							icon.infoShadowAnchor = new GPoint(18, 25);

							var marker = new GMarker(point, icon);
							GEvent.addListener(marker, "click", function() {
								marker.openInfoWindowHtml(address);
							});
							map.addOverlay(marker);

							// bind a search control to the map, suppress result list
							map.addControl(new google.maps.LocalSearch(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,20)));
						}
					}
				);
			}
		}
	}

