Geolokalizacja oparta na HTML5.
Przykład działania: map.LocoGroup.com

<?php $ClientIp = $_SERVER['REMOTE_ADDR']; ?>
<style>html,body,#map{height:100%;margin:0px;padding:0px}</style>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<div id="map"></div>
<script>
if (navigator.geolocation) {
var timeoutVal = 10 * 1000 * 1000;
navigator.geolocation.getCurrentPosition(
displayPosition, 
displayError, {enableHighAccuracy: true, timeout: timeoutVal, maximumAge: 0});
} else {
alert("Geolocation is not supported by this browser!");
}
function displayPosition(position) {
var pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var options = {zoom: 15, center: pos, mapTypeId: google.maps.MapTypeId.ROADMAP};
var map = new google.maps.Map(document.getElementById("map"), options);
var marker = new google.maps.Marker({position: pos, map: map, title: "your location"});
var contentString = "<b>Your IP</b>: <?php echo $ClientIp; ?><br /><b>Timestamp</b>: " + parseTimestamp(position.timestamp) + "<br/><b>Your location</b>: LAT " + position.coords.latitude + ", LONG " + position.coords.longitude + ", ACCURACY " + position.coords.accuracy;
var infowindow = new google.maps.InfoWindow({content: contentString});
google.maps.event.addListener(marker, 'click', function() {infowindow.open(map,marker);});
}
function displayError(error) {
var errors = { 
1: 'Your location - permission denied.',
2: 'Your location - position unavailable.',
3: 'Your location - request timeout.'
};
alert("Error: " + errors[error.code]);
}
function parseTimestamp(timestamp) {
var d = new Date(timestamp);
var day = d.getDate();
var month = d.getMonth() + 1;
var year = d.getFullYear();
var hour = d.getHours();
var mins = d.getMinutes();
var secs = d.getSeconds();
var msec = d.getMilliseconds();
return year + "-" + month + "-" + day + " | " + hour + ":" + mins + ":" + secs + "." + msec;
}
</script>

Facebook Comments

Zostaw komentarz

Twój adres email nie zostanie opublikowany. Pola, których wypełnienie jest wymagane, są oznaczone symbolem *

ZOBACZ RÓWNIEŻ

WCZYTYWANIE KONTENTU Z INNEJ LOKALIZACJI JQUERY

Wczytywanie zawartości pliku lub adresu URL z innej