Niçin kullanacaksın, sitene giren insanların konumunu mu göstereceksin yoksa başka bir amacın mı var?
Lang ve Lat değerini alabiliyorsun ama kullanıcının izin vermiş olması gerek. Kodları gönderiyorum ama bu işlem için JS kullanıyorsun.Kişi butona tıkladığında kişi yol tarifi verecek Google Maps'te.
Gönderiyorum derken anlayamadım özür dilerim.Lang ve Lat değerini alabiliyorsun ama kullanıcının izin vermiş olması gerek. Kodları gönderiyorum ama bu işlem için JS kullanıyorsun.
var userLocationLat = "0,000000000";
var userLocationLon = "0,000000000";
function getLocation() {
if (navigator.geolocation)
navigator.geolocation.getCurrentPosition(showPosition, showError);
else
console.log("Geolocation is not supported by this browser.");
}
function showPosition(position) {
userLocationLat = position.coords.latitude;
userLocationLon = position.coords.longitude;
}
function showError(error) {
if (error.code == 1)
console.log("User denied the request for Geolocation.");
else if (err.code == 2)
console.log("Location information is unavailable.");
else if (err.code == 3)
console.log("The request to get user location timed out.");
else
console.log("An unknown error occurred.");
}
$(document).ready(function () {
getLocation();
});
userLocationLat
ve userLocationLon
değişkenlerinde konumu verecektir.Kodu yükleyemedim. Geç gitti mesajım.Gönderiyorum derken anlayamadım özür dilerim.
JavaScript:var userLocationLat = "0,000000000"; var userLocationLon = "0,000000000"; function getLocation() { if (navigator.geolocation) navigator.geolocation.getCurrentPosition(showPosition, showError); else. console.log("Geolocation is not supported by this browser."); } function showPosition(position) { userLocationLat = position.coords.latitude; userLocationLon = position.coords.longitude; } function showError(error) { if (error.code == 1) console.log("User denied the request for Geolocation."); else if (err.code == 2) console.log("Location information is unavailable."); else if (err.code == 3) console.log("The request to get user location timed out."); else. console.log("An unknown error occurred."); } $(document).ready(function () { getLocation(); });
Bu kod sanauserLocationLat
veuserLocationLon
değişkenlerinde konumu verecektir.
Kodu yükleyemedim. Geç gitti mesajım.
Hayır, değil. HTML'e import ettikten sonra yol tarifini de JS'ten açtırman lazım ki konuma erişebil ya da bu değerleri gizli bir inputa yazdırıp oradan okuyabilirsin.Teşekkürler fakat burada HTML dokümanına erişebildiğimiz bir kod yok direk script dosyası oluşturup import etmem yeterli mi?
setInterval()
fonksiyonu ile getLocation 2 saniyede bir çalıştırabilirsin.Bu sitenin çalışmasını sağlamak için gerekli çerezleri ve deneyiminizi iyileştirmek için isteğe bağlı çerezleri kullanıyoruz.