
HTML5 ile gelen özelliklerden Geolocation API kullanımına ait örnek kodu sizlere sunuyorum. Örnekle ziyaretçilere o anda bulunduğu konum bilgisini haritada gösterebilirsiniz.
Güle güle kullanın.
// HTML CODE
0 <!DOCTYPE html> 1 2 3 4 5 6 #haritam{height: 800px;width: 1500px;} 7 8 9 10 if (navigator.geolocation) { 11 navigator.geolocation.getCurrentPosition(showCurrentLocation); 12 } else { 13 alert("Geolocation API DESTEKLENMIYOR"); 14 } 15 16 function showCurrentLocation(position) { 17 var latitude = position.coords.latitude; 18 var longitude = position.coords.longitude; 19 var coords = new google.maps.LatLng(latitude, longitude); 20 var mapOptions = { 21 zoom: 20, 22 center: coords, 23 mapTypeControl: true, 24 mapTypeId: google.maps.MapTypeId.ROADMAP 25 }; 26 map = new google.maps.Map(document.getElementById("haritam"), mapOptions); 27 var marker = new google.maps.Marker({ 28 position: coords, 29 map: map, 30 title: "BULUNDUĞUM YER" 31 }); 32 } 33 34 35 36 37 38