non so se può esserti di aiuto:
nella form di registrazione ho rispettivamente:
-provincia
-comune
-indirizzo (testo libero) con un evento onblur="showAddress()"
tale metodo si trova nel googleUtils.js...
codice:
<tr>
<td nowrap="nowrap" align="right"><label class="label">Indirizzo</label></td>
<td nowrap="nowrap" align="right"><input type="text" name="txt_indirizzo" id="txt_indirizzo" onblur="showAddress()"/></td>
<script type="text/javascript" src="phpUtils/googleUtils.js"></script>
<td nowrap="nowrap" align="left"><label id="obblig_indirizzo" style="display:none" class="labelmissing"/>*</label></td>
</tr>
googleUtils.js
codice:
// JavaScript Document
//key google map: ABQIAAAAylyUSiWf0T-Vpicn0c1oHxSn6THA6mDGXfWJc9aerBXvDGjVbRRQ8XMQf2xWPSkZYbb0HrXV2c3-KA
var geocoder = new GClientGeocoder();
var indirizzo = document.getElementById("txt_indirizzo");
var citta = document.getElementById("txt_citta");
var provincia = document.getElementById("txt_provincia");
function showAddress() {
var address = indirizzo.value + " " + citta.value + " " + provincia.value;
var latitude = document.getElementById("hdn_latitude");
var longitude = document.getElementById("hdn_longitude");
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
latitude.value = point.lat();
longitude.value = point.lng();
}
}
);
}
}
//<![CDATA[
var map;
var geocoder;
function load() {
if (GBrowserIsCompatible()) {
geocoder = new GClientGeocoder();
map = new GMap2(document.getElementById('map'));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(40, -100), 4);
}
}
function searchLocations() {
var address = document.getElementById('addressInput').value;
geocoder.getLatLng(address, function(latlng) {
if (!latlng) {
alert(address + ' not found');
} else {
searchLocationsNear(latlng);
}
});
}
function searchLocationsNear(center) {
var radius = document.getElementById('radiusSelect').value;
var searchUrl = 'phpUtils/phpsqlsearch_genxml.php?lat=' + center.lat() + '&lng=' + center.lng() + '&radius=' + radius;
GDownloadUrl(searchUrl, function(data) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName('marker');
map.clearOverlays();
var sidebar = document.getElementById('sidebar');
sidebar.innerHTML = '';
if (markers.length == 0) {
sidebar.innerHTML = 'Nessun risultato trovato';
map.setCenter(new GLatLng(40, -100), 7);
return;
}
var bounds = new GLatLngBounds();
for (var i = 0; i < markers.length; i++) {
var nome = markers[i].getAttribute('nome');
var cognome = markers[i].getAttribute('cognome');
var address = markers[i].getAttribute('address');
var distance = parseFloat(markers[i].getAttribute('distance'));
var point = new GLatLng(parseFloat(markers[i].getAttribute('lat')),
parseFloat(markers[i].getAttribute('lng')));
var marker = createMarker(point, nome, cognome, address);
map.addOverlay(marker);
var sidebarEntry = createSidebarEntry(marker, nome, cognome, address, distance);
sidebar.appendChild(sidebarEntry);
bounds.extend(point);
}
map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
});
}
function createMarker(point, nome, cognome, address) {
var marker = new GMarker(point);
var html = '' + nome + ' ' + cognome + '
' + address;
GEvent.addListener(marker, 'click', function() {
marker.openInfoWindowHtml(html);
});
return marker;
}
function createSidebarEntry(marker, nome, cognome, address, distance) {
var div = document.createElement('div');
var html = '' + nome + ' ' + cognome +' (' + distance.toFixed(1) + ')
' + address;
div.innerHTML = html;
div.style.cursor = 'pointer';
div.style.marginBottom = '5px';
GEvent.addDomListener(div, 'click', function() {
GEvent.trigger(marker, 'click');
});
GEvent.addDomListener(div, 'mouseover', function() {
div.style.backgroundColor = '#eee';
});
GEvent.addDomListener(div, 'mouseout', function() {
div.style.backgroundColor = '#fff';
});
return div;
}
//]]>