/** * Javascript that controls behavior of external components. */ var mapH, markerH, positionH; var geocoder; var timeout = 100; var lock = true; var first = true; var solHQ = new google.maps.LatLng(44.813209013839284, 20.464512819311494); var lockText = 'Lock marker'; var coorText = 'Coordinates'; var buttonText = 'Geocode'; function initialize() { geocoder = new google.maps.Geocoder(); markerH = new google.maps.Marker(); var myOptions = { zoom : 14, center : solHQ, scaleControl : true, mapTypeId : google.maps.MapTypeId.ROADMAP }; var canvasId = "map_canvasH"; var coorId = "coordinatesH"; mapH = new google.maps.Map(document.getElementById(canvasId), myOptions); positionH = coordinatesControl(mapH); geocode(mapH); lockMarkerControl(mapH); google.maps.event.addListener(mapH, 'click', function(event) { if (!lock) { var coor = document.getElementById(coorId); markerH.setPosition(event.latLng); markerH.setMap(mapH); coor.value = event.latLng; positionH.innerHTML = parseLatLng(event.latLng); var address = document.getElementById("addressH"); var city = document.getElementById("cityH"); var country = document.getElementById("countryH"); codeLatLng(event.latLng, address, city, country); coor.focus(); coor.blur(); } }); drawMap(); } function codeLatLng(latlng, address, city, country) { geocoder.geocode({ 'latLng' : latlng }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { if (results[0]) { var ac = results[0].address_components; var str = "", num = "", cty = "", cnt = ""; for ( var i in ac) { if (ac[i].types[0] == "street_number") num = ac[i].long_name; if (ac[i].types[0] == "street_address" || ac[i].types[0] == "route" || ac[i].types[0] == "intersection") str = ac[i].long_name; if (ac[i].types[0] == "locality") cty = ac[i].long_name; if (ac[i].types[0] == "country") cnt = ac[i].long_name; } address.value = str + " " + num; city.value = cty; country.value = cnt; address.focus(); address.blur(); city.focus(); city.blur(); country.focus(); country.blur(); } } else { alert("Geocoder failed due to: " + status); } }); } function codeAddress(address, coor) { geocoder.geocode({ 'address' : address }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { coor.value = results[0].geometry.location; coor.focus(); coor.blur(); drawMap(); } }); } function parseLatLng(latLng) { if (latLng === "") return coorText + " ( - )"; var dec = 1000000; var ll = new Array(); ll = latLng.toString().substring(1, latLng.toString().length - 1).split(', '); return coorText + " (" + (Math.round(parseFloat(ll[0]) * dec) / dec) + ", " + (Math.round(parseFloat(ll[1]) * dec) / dec) + ")"; } function coordinatesControl(map) { var controlDiv = document.createElement('DIV'); controlDiv.id = 'mapsCoor'; map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(controlDiv); return controlDiv; } function geocode(map) { var button = document.createElement('button'); button.id = 'geocodeButton'; button.innerHTML = buttonText; map.controls[google.maps.ControlPosition.TOP_RIGHT].push(button); var address = document.getElementById("addressH"); var city = document.getElementById("cityH"); var country = document.getElementById("countryH"); google.maps.event.addDomListener(button, 'click', function() { var fullAddress = address.value + ' ' + city.value + ' ' + country.value; var coor = document.getElementById("coordinatesH"); codeAddress(fullAddress, coor); }); } function lockMarkerControl(map) { var controlDiv = document.createElement('DIV'); controlDiv.id = 'mapsCheckbox'; var cb = document.createElement('input'); cb.type = 'checkbox'; cb.checked = lock; controlDiv.innerHTML = '