Ciao a tutti!
Stavo provando a modificare un esempio di geolocalizzazione tramite HTML5 e non ho riscontrato problemi.
Ho una domanda però.. Nello script che ho, chiedo le coordinate dell'utente e tramite gMaps mostro l'indirizzo, la città e tutto il resto.
Come posso stampare l'indirizzo dell'utente o la città? Riesco a stampare soltanto le coordinate![]()
Grazie in anticipo per l'aiutocodice:<html> <head> <title>Geolocalizzazione con HTML5</title> <script src="http://maps.google.com/maps/api/js?sensor=true"></script> <script> function mostraPosizione(){ if(navigator.geolocation) { function getPosition(position) { var point = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); var titlemarker = "Tu sei qui! " + "Latitudine: " + position.coords.latitude+ " " + "Longitudine: " + position.coords.longitude+" " + "Precisione: " + position.coords.accuracy ; myOptions = { zoom: 15, center: point, mapTypeId: google.maps.MapTypeId.ROADMAP }, mapDiv = document.getElementById("mapDiv"), map = new google.maps.Map(mapDiv, myOptions), marker = new google.maps.Marker({ position: point, map: map, title: "Sei qui!" }); var infowindow = new google.maps.InfoWindow({ content: titlemarker }); google.maps.event.addListener(marker, 'click', function() { infowindow.open(map,marker); }); } function handle_errors(error){ switch(error.code) { case error.PERMISSION_DENIED: alert("L''utente non ha condiviso i dati per la geolocalizzazione"); break; case error.POSITION_UNAVAILABLE: alert("Non è possibile determinare la posizione attuale"); break; case error.TIMEOUT: alert("Time Out nel determinare la posizione"); break; default: alert("Errore sconosciuto"); break; } } navigator.geolocation.getCurrentPosition(getPosition,handle_errors); } } mostraPosizione(); </script> <style> #mapDiv { width:600px; height:400px; border:1px solid #efefef; margin:auto; -moz-box-shadow:5px 5px 10px #000; -webkit-box-shadow:5px 5px 10px #000; } </style> </head> <body onload="mostraPosizione();"> <div id="mapDiv"></div> </body> </html>
Thinker


Rispondi quotando
