
var geocoder = new GClientGeocoder();

var tentativas_maximas = 30;

function marcarEndereco(address, texto, tentativa) {

	if (tentativa == null) {
		tentativa = 1;
	}

  geocoder.getLatLng(address, function(point) {
	  if (!point) {

		if (tentativa <= tentativas_maximas) {
			marcarEndereco(address, texto, tentativa + 1);
		}
		else {
			$('#error-container').append("Endereço '" + address + "' não encontrado.<BR>");
		}
	  }
	  else {
		var marker = new GMarker(point);
		marker.text = texto;
		GEvent.addListener(marker, "click", function () {marker.openInfoWindowHtml(texto);});
		map.addOverlay(marker);
	  }
	} // end function;
  ); // end getLatLng;
} // end marcarEndereco;


function centralizar (address, zoom, tentativa) {

	if (tentativa == null) {
		tentativa = 1;
	}


  geocoder.getLatLng(address, function(point) {
	  if (!point) {
		if (tentativa <= tentativas_maximas) {
			centralizar(address, zoom, tentativa + 1);
		}
		else {
			$('#error-container').append("centralizar: Endereço '" + address + "' não encontrado.<BR>");
		}
	  }
	  else {
		map.setCenter(point, zoom);
	  }
	} // end function;
  ); // end getLatLng;
} // end marcarEndereco;


