Last active
November 3, 2015 13:00
-
-
Save igorbenic/a4735628fe7f1c390224 to your computer and use it in GitHub Desktop.
Geo Pozicioniranje u HTML-u
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pokaziGresku(greska) { | |
switch (greska.code) { | |
case greska.PERMISSION_DENIED: | |
prikaziPoruku("Korisnik nije dopustio dohvat Geolokacije."); | |
break; | |
case greska.POSITION_UNAVAILABLE: | |
prikaziPoruku("Informacije lokacije nije dostupna."); | |
break; | |
case greska.TIMEOUT: | |
prikaziPoruku("Zahtjev za dohvaćanje lokacije korisnike je istekao."); | |
break; | |
case greska.UNKNOWN_ERROR: | |
prikaziPoruku("Došlo je do nepoznate greške."); | |
break; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function () { | |
dohvatiLokaciju(); | |
}); | |
function podrzavaGeolokaciju() { | |
return 'geolocation' in navigator; | |
} | |
function prikaziPoruku(message) { | |
$('#message').html(message); | |
} | |
function dohvatiLokaciju() { | |
if (podrzavaGeolokaciju()) { | |
navigator.geolocation.getCurrentPosition(pokaziPoziciju); | |
} | |
else { | |
prikaziPoruku("Geolokacija nije podržana."); | |
} | |
} | |
function pokaziPoziciju(position) { | |
var datetime = new Date(position.timestamp).toLocaleString(); | |
prikaziPoruku("Latitude: " + position.coords.latitude + "<br />" | |
+ "Longitude: " + position.coords.longitude + "<br />" | |
+ "Timestamp: " + datetime); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<title></title> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | |
<script src="geo.js"></script> | |
</head> | |
<body> | |
<div id="message"> | |
</div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function podrzavaGeolokaciju(){ | |
return 'geolocation' in navigator; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment