Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > it.comp.lang.javascript > #8179

problema di geocoding

From Roberto Tagliaferri <tagliaferri@bofhland.org>
Newsgroups it.comp.lang.javascript
Subject problema di geocoding
Date 2017-02-22 09:04 +0100
Organization C.U. srl News Server
Message-ID <o8jglt$urb$1@virtdiesel.mng.cu.mi.it> (permalink)

Show all headers | View raw


Hola.. ho un  problema con uno script per il geocoding.
In sintesi la procedura via ajax (un banale ajaxsubmit) manda un file csv con le località ad uno script php.
Lo script se nel file non trova le coordinate parcheggia i dati in un array, alla fine l'array viene rispedito al javascript che manda tutto a google.
C'è un delay di 30msec per evitare il limte di 50 query al secondo.
Funziona tutto, a parte che fa 10 geocoding a volta.
Se ripasso il file ne fa altri 10.. nelle faq sui limiti parla di rate limit e di limite giornaliero.

Il codice:
function risposta_importa_partner(d, b) {
	loader(0);
	bootbox.hideAll();
	$('#id_finestra_geo').html(''); //per l'output degli errori
	eval("var t=" + d + ";"); //decodifica array json
	var tmp = '';
	if (t.codice == 'OK') {
		//geocoding
		geocoder = new google.maps.Geocoder();
		$.each(t.indirizzi, function (k, v) {
			if (v != '**FINE**') { //marcatore di fine lista
				sleep(30);
				tmp = $('#id_finestra_geo').html();
				geocoder.geocode({'address': v, 'region': 'IT'}, function (results, status) {

					if (status == google.maps.GeocoderStatus.OK) {
						var st = new String(results[0].geometry.location);
						var st1 = st.replace(")", "");
						var st2 = st1.replace('(', '');

						var comune = '';
						if (results[0].address_components[0].types[0] == 'locality') {
							comune = results[0].address_components[0].long_name;
						} else if (results[0].address_components[1].types[0] == 'locality') {
							comune = results[0].address_components[1].long_name;
						} else if (results[0].address_components[2].types[0] == 'locality') {
							comune = results[0].address_components[2].long_name;
						} else {
							comune = results[0].address_components[3].long_name;
						}
						$.post("includes/jq_edit.php", {
							comando: 'aggiorna_coordinate_partner_file',
							id: k,
							coordinate: st2
						});
						tmp += "<font color=green>" + k + ":Importato indirizzo " + v + "</font>";
						//alert(results[0].address_components[2].long_name);
					} else {
						tmp += "<font color=red>" + k + ":errore in  " + v + "</font>";

					}
					tmp += "<br />";
					$('#id_finestra_geo').html(tmp);
				});
			} else {
				tmp = $('#id_finestra_geo').html();
				tmp += v + "<br />";
				$('#id_finestra_geo').html(tmp);


			}
		});
		messaggio("File in importazione (" + t.quanti + " inviati a google e " + t.numero + "  importati direttamente)", 'ok', '3500');


	} else if (t.msg) {
		messaggio(t.msg, 'errore', 2500);
	}
}


-- 
Roberto Tagliaferri-Linux user #30785 <-> r.tagliaferri@(forse)tosnet.it
www.robyt.eu

Back to it.comp.lang.javascript | Previous | Next | Find similar


Thread

problema di geocoding Roberto Tagliaferri <tagliaferri@bofhland.org> - 2017-02-22 09:04 +0100

csiph-web