/***************************************************** * File: geocode.js * * Google maps api v3 script by Неделчо Николов created on 25 Септември 2012 г. *********************************************************/ var _mMapCopy = "Map data \x26#169;2008 "; var _mSatelliteCopy = "Imagery \x26#169;2008 "; if(document.getElementById('wrapper') == 'null') { document.getElementById('wrapper').style.display='none'; document.getElementById('wrapper').style.visibility='hidden'; } if(document.getElementById('map_outer') == 'null') { document.getElementById('map_outer').style.display='none'; } //var geocoder = null; //var map = null; //var image = '/images/pointer.png'; //var shadow = '/images/pointer_shadow.png'; var map = null; var marker = null; var geocoder = null; var infowindow = null; function initialize() { console.log('initialize()'); map = new google.maps.Map(document.getElementById('map'), { center: new google.maps.LatLng(42.6976262, 23.3222839), zoom: 15, disableDefaultUI: true, zoomControl: true, mapTypeControl: false, mapTypeId: google.maps.MapTypeId.ROADMAP }); geocoder = new google.maps.Geocoder(); infowindow = new google.maps.InfoWindow({pixelOffset: new google.maps.Size(0,-34)}); } function initialize_old() { geocoder = new google.maps.Geocoder(); var latlng = new google.maps.LatLng(42.6976262, 23.3222839); var mapOptions = { zoom: 17, center: latlng, disableDefaultUI: true, zoomControl: true, mapTypeControl: true, mapTypeId: google.maps.MapTypeId.ROADMAP } marker = new google.maps.Marker({ map:map, draggable:true, animation: google.maps.Animation.DROP, position: latlng }); map = new google.maps.Map(document.getElementById("map"), mapOptions); } function codeAddress(address, nbCalls) { if (typeof nbCalls == 'undefined') { nbCalls = 1; } console.log('codeAddress', nbCalls); if(typeof geocoder != 'undefined' && geocoder != null) { codeAddressWhenMapsISLoaded(address); }else if (nbCalls < 10) { setTimeout(codeAddress.bind(this, address, nbCalls + 1), 1000); } } function codeAddressWhenMapsISLoaded(address) { console.log('codeAddressWhenMapsISLoaded', address); geocoder.geocode({ 'address': address }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); content = results[0].formatted_address; infowindow.setContent(content); if (marker && marker.setPosition) { marker.setPosition(results[0].geometry.location); } else { marker = new google.maps.Marker({ map: map, icon: { url: 'http://maps.google.com/mapfiles/arrow.png', anchor: new google.maps.Point(10, 34) }, position: results[0].geometry.location }); google.maps.event.addListener(marker, 'click', function(evt) { infowindow.open(map); }); } infowindow.setPosition(results[0].geometry.location); infowindow.open(map); } else { console.log('Your search was not successful for the following reason: ' + status); } }); } function codeAddress_old(address) { geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); var marker = new google.maps.Marker({ map: map, animation: google.maps.Animation.DROP, icon: image, shadow: shadow, position: results[0].geometry.location }); function toggleBounce() { if (marker.getAnimation() != null) { marker.setAnimation(null); } else { marker.setAnimation(google.maps.Animation.BOUNCE); } } google.maps.event.addListener(marker, 'click', toggleBounce); $('#map').css('display','block'); $('#map_outer').css('display','block'); $('#map_outer').css('padding','2px'); if(ie) { $('#map_outer').css('width','auto'); } else { $('#map_outer').css('width','202px'); } $('#map_outer').css('height','202px'); $('#map_outer').css('background','#ffffff'); $('#map_outer').css('borderWidth','2px'); $('#map_outer').css('borderColor','#46427F'); $('#wrapper').css('display','block'); $('#wrapper').css('width','242px'); $('#wrapper').css('padding','0px'); var all = results[0].geometry.location; var latitude = all.lat(); var longitude = all.lng(); $.ajax({ url: "/ajax_geocode.php", type: "POST", dataType: "html", async: 'true', data: {lat: latitude, lng: longitude, subscr: subscr} }); } else { alert("Geocode was not successful for the following reason: " + status); } }); } function codeAddressGC(lat, lng) { //alert(lat, lng); console.log('codeAddressGC'); var latlng = new google.maps.LatLng(lat, lng); map.setCenter(latlng); var marker = new google.maps.Marker({ map: map, animation: google.maps.Animation.DROP, icon: image, shadow: shadow, position: latlng }); google.maps.event.addListener(marker, 'click', toggleBounce); function toggleBounce() { if (marker.getAnimation() != null) { marker.setAnimation(null); } else { marker.setAnimation(google.maps.Animation.BOUNCE); } } $('#map').css('display','block'); $('#map_outer').css('display','block'); $('#map_outer').css('padding','2px'); if(ie) { $('#map_outer').css('width','auto'); } else { $('#map_outer').css('width','202px'); } $('#map_outer').css('height','202px'); $('#map_outer').css('background','#ffffff'); $('#map_outer').css('borderWidth','2px'); $('#map_outer').css('borderColor','#46427F'); $('#wrapper').css('display','block'); $('#wrapper').css('width','242px'); $('#wrapper').css('padding','0px'); }