/*
 * TZ 2009-02-18
 * Hilfsfunktionen für GoogleMaps. 
 */

var GEOCODER = new google.maps.Geocoder();
var MAP_ZOOM_LEVEL = 14;
var MAP_OPTIONS = {
        zoom: 14,
        mapTypeId: google.maps.MapTypeId.ROADMAP
};

//GEOCODER.setCache(null);

/**
 * Fragt die Koordinaten für address bei GoogleMaps an und initialisiert eine
 * GoogleMap im Element map.
 * 
 * @param address Adresse als String.
 * @param mapContainer DOMElement, in dem die GoogleMap dargestellt wird. 
 */
function showMapWithAddress(address, mapContainer) {
	 //console.info("Suche Koordinaten fuer: " + address + "...");
	//console.time("showAddress");
    
    var map = new google.maps.Map(mapContainer, MAP_OPTIONS);
	
	GEOCODER.geocode({"address": address}, function(results, status) {
		if (status != google.maps.GeocoderStatus.OK) {
			//console.log("GMap geocode() failed");
            
        } else {
            var location = results[0].geometry.location;
            //console.debug(response);
            //console.info('...gefunden: ' + location.Point.coordinates[1] + "|" + location.Point.coordinates[0]);
            
            if (location) {
                map.setCenter(location);
                var marker = new google.maps.Marker({
                    map: map,
                    position: location
                });
            }
            //console.timeEnd("showAddress");
        }
    });
}
