function initialize() { var locations = []; } function loadScript() { var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'https://maps.googleapis.com/maps/api/js?v=3&' + 'callback=initialize&key=AIzaSyCOOurFLLOx-1jgS5JRdnnw2pis0uop6VE'; document.body.appendChild(script); } window.onload = loadScript; $(document).ready(function(){ $('#getcoords').click(function() { if (confirm('ATTENZIONE\nLa ricerca automatica delle coordinate cancellera\ndefinitivamente le coordinate preimpostate.\n \n VUOI CONTINUARE?')) { var user1Location = $("#fulladdress").val(); var geocoder = new google.maps.Geocoder(); //convert location into longitude and latitude geocoder.geocode({ address: user1Location }, function(locResult) { console.log(locResult); var lat1 = locResult[0].geometry.location.lat(); var lng1 = locResult[0].geometry.location.lng(); lat1 = lat1.toString().substring(0, 10); lng1 = lng1.toString().substring(0, 10); $('#latitude').val(lat1); $('#longitude').val(lng1); /* newmarkers = new google.maps.Marker({ position: new google.maps.LatLng(lat1, lng1), map: map });*/ $('#imagenewmap').attr('src','https://maps.googleapis.com/maps/api/staticmap?maptype=hybrid¢er='+lat1+','+lng1+'&markers='+lat1+','+lng1+'&zoom=17&size=320x240&key=AIzaSyCOOurFLLOx-1jgS5JRdnnw2pis0uop6VE'); }); return false; } }); $('#getnewcoords').click(function() { if (confirm('ATTENZIONE\nLa ricerca automatica delle coordinate cancellera\ndefinitivamente le coordinate preimpostate.\n \n VUOI CONTINUARE?')) { var user1Location = $("#fulladdress").val(); //var user1Location = 'via del forno 3, felettino, la spezia (SP)'; var geocoder = new google.maps.Geocoder(); //convert location into longitude and latitude geocoder.geocode({ address: user1Location }, function(locResult) { console.log(locResult[0]); var lat1 = locResult[0].geometry.location.lat(); var lng1 = locResult[0].geometry.location.lng(); lat1 = lat1.toString().substring(0, 10); lng1 = lng1.toString().substring(0, 10); $('#latitude').val(locResult[0].geometry.location); $('#longitude').val(locResult[0].geometry.location); console.log(''); $('#imagenewmap').attr('src','https://maps.googleapis.com/maps/api/staticmap?maptype=hybrid¢er='+lat1+','+lng1+'&markers='+lat1+','+lng1+'&zoom=17&size=320x240&key=AIzaSyCOOurFLLOx-1jgS5JRdnnw2pis0uop6VE'); }); return false; } }); $('#setcoords').click(function() { $('#imagenewmap').attr('src','https://maps.googleapis.com/maps/api/staticmap?maptype=hybrid¢er='+$('#latitude').val()+','+$('#longitude').val()+'&markers='+$('#latitude').val()+','+$('#longitude').val()+'&zoom=17&size=320x240&key=AIzaSyCOOurFLLOx-1jgS5JRdnnw2pis0uop6VE'); }); /* $('#imagenewmap').click(function(e) { var offset = $(this).offset(); $('#latitude').val($('#latitude').val()*1 - (Math.round(e.pageY - offset.top -120)) /120000); $('#longitude').val($('#longitude').val()*1 + (Math.round(e.pageX - offset.left)-160) /90000); $(this).attr('src','https://maps.googleapis.com/maps/api/staticmap?maptype=hybrid¢er='+$('#latitude').val()+','+$('#longitude').val()+'&markers='+$('#latitude').val()+','+$('#longitude').val()+'&zoom=17&size=320x240&key=AIzaSyCOOurFLLOx-1jgS5JRdnnw2pis0uop6VE'); });*/ });