2010-09-04 16 views
11

Sto utilizzando l'API di geolocalizzazione HTML5 per trovare la longitudine e la latitudine dagli utenti del mio sito. Funziona, ma ora mi piacerebbe mostrare sullo schermo "Sei davvero in ...". Quindi ho bisogno di convertire queste coordinate che ottengo dall'API di geolocalizzazione in un nome di luogo.Converti le coordinate in un nome di luogo

Ho provato un po 'con l'API di Google Maps, ma non ho funzionato.

Qualcuno sa come farlo.

Questo è il mio codice finora

<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true&amp;key=ABQIAAAA55ubMQxcIybj35yHYV_iGRTrPfqOlZVmBxwB40M45alaTGbn0hTaoOvTqt2CB0iR6c1SkxYmRqRvHA" type="text/javascript"></script> 

    <script type="text/javascript"> 


      // When loaded go to: 
      initiate_geolocation(); 

      function initiate_geolocation() { 
       navigator.geolocation.getCurrentPosition(handle_geolocation_query,handle_errors); 
      } 

      function handle_errors(error) 
      { 
       switch(error.code) 
       { 
        case error.PERMISSION_DENIED: document.getElementById("geo").innerHTML = "User did not share geolocation data"; 
        break; 

        case error.POSITION_UNAVAILABLE: document.getElementById("geo").innerHTML = "Could not detect current position"; 
        break; 

        case error.TIMEOUT: document.getElementById("geo").innerHTML = "retrieving geolocation position timed out"; 
        break; 

        default: document.getElementById("geo").innerHTML = "unknown geolocation error"; 
        break; 
       } 
      } 

      function handle_geolocation_query(position){ 
       document.getElementById("geo").innerHTML = "Your coordinates are " + position.coords.latitude + ", " + position.coords.longitude; 

var geoCoder = new GClientGeocoder(); 

    geoCoder.getLocations(new GLatLng(position.coords.latitude, position.coords.longituder, true), getPositionName()); 


      } 

function getPositionName(response) 
{ 
// 
// Here I don't know what to do 
// 
} 
    </script> 

Grazie,
Vincent

risposta

Problemi correlati