Afisare locatie vizitator cu geolocation

Discutii si intrebari legate de scripturi si functii JavaScript, jQuery si Ajax, cod JavaScript in general.
bogdaneu
Mesaje: 5

Afisare locatie vizitator cu geolocation

Marplo,
si acum intrebarea de nota 10. Am instalat un script de geolocatie.
unde pot sa trec parametrii pe care-i scoate scriptul pentru afisearea automata a locatiei vizitatorului?
problema este ca nu ma descurc deloc cu progrmarea pe obiecte.
Stiu ca nu te cunosc si nu pot sa-ti dau o bere, dar daca o rezolvi o sa dau acatiste pentru tine la biserica 1 an de acum incolo...:)
multumesc!

MarPlo Mesaje: 4343
Salut
Nu am experienta cu geolocation, nu am folosit acel obiect.
Totusi, la pagina asta gasesti documentatie si exemplu: Using geolocation

- Cred ca e ceva folositor :), cum majoritatea suntem cam rataciti de noi insine; cand vrem sa ne regasim, ne va arata locatia unde sa ne cautam :? .

MarPlo Mesaje: 4343
Din curiozitate, m-am jucat putin cu obiectul geolocation in JavaScript si a rezultat acest script; poate e de folos.

Cod: Selectaţi tot

Click this button to show a map with geolocation of your internet connection.<br>
<button id="get_geoloc">Show Geolocation</button>
<div id="geoloc_resp"></div>
<script>
function showGeoLoc(){
  var geoloc_resp = document.getElementById('geoloc_resp');  //element to add geolocation response

  //if the browser not support geolocation, show message
  if(!navigator.geolocation){
    geoloc_resp.innerHTML ='Geolocation is not supported by your browser';
    return;
  }

  geoloc_resp.innerHTML ='LOADING...';

  //get latitude and longitude position
  navigator.geolocation.getCurrentPosition(function(position){
    var latt = position.coords.latitude;
    var long = position.coords.longitude;
    var img_size = {w:400, h:350};  //image size

    //add in #geoloc_resp google map image with location
    geoloc_resp.innerHTML ='Latitude is: '+ latt +'<br>Longitude is: '+ long +'<br><img src="https://maps.googleapis.com/maps/api/staticmap?center='+ latt +','+ long +'&zoom=14&size='+ img_size.w +'x'+ img_size.h +'&markers=color:red|size:mid|'+ latt +','+ long +'" alt="Google map location" width="'+ img_size.w +'" height="'+ img_size.h +'" />';
  }, function(err){
    //in case or error, show error message and its code
    geoloc_resp.innerHTML ='Unable to retrieve your location.<br>Error code: '+ err.code +'<br>Error message: '+ err.message;
  });
}

//register click event to button to call showGeoLoc() function
var get_geoloc = document.getElementById('get_geoloc');
if(get_geoloc) get_geoloc.addEventListener('click', showGeoLoc);
</script>
Demo:
Click this button to show a map with geolocation of your internet connection.

Subiecte similare