You need to sign in to do that
Don't have an account?
sawaji varun
how to display current location address using longitude and latitude
<apex:page >
<script src="http://www.google.com/jsapi?key=ABQIAAAAlJFc1lrstqhgTl3ZYo38bBQcfCcww1WgMTxEFsdaTsnOXOVOUhTplLhHcmgnaY0u87hQyd-n-kiOqQ"></script>
<script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<html>
<body>
<p id="demo">Click the button to get your position.</p>
<button onclick="getLocation()">Check-In</button>
<div id="mapholder"></div>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, showError);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
alert('some');
var latlon = position.coords.latitude + "," + position.coords.longitude;
var img_url = "http://maps.googleapis.com/maps/api/staticmap?center="
+latlon+"&zoom=14&size=400x300&sensor=false";
document.getElementById("mapholder").innerHTML = "<img src='"+img_url+"'>";
}
function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
x.innerHTML = "User denied the request for Geolocation."
break;
case error.POSITION_UNAVAILABLE:
x.innerHTML = "Location information is unavailable."
break;
case error.TIMEOUT:
x.innerHTML = "The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
x.innerHTML = "An unknown error occurred."
break;
}
}
</script>
<p id="demo1">Click the button to get your position.</p>
<button onclick="getLocation1()">Check-Out</button>
<div id="mapholder1"></div>
<script>
function getLocation1() {
var x1 = document.getElementById("demo1");
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition1, showError1);
} else {
x1.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition1(position) {
alert('here');
var latlon1 = position.coords.latitude + "," + position.coords.longitude;
var img_url1 = "http://maps.googleapis.com/maps/api/staticmap?center="
+latlon1+"&zoom=14&size=400x300&sensor=false";
document.getElementById("mapholder1").innerHTML = "<img src='"+img_url1+"'>";
}
function showError1(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
x1.innerHTML = "User denied the request for Geolocation."
break;
case error.POSITION_UNAVAILABLE:
x1.innerHTML = "Location information is unavailable."
break;
case error.TIMEOUT:
x1.innerHTML = "The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
x1.innerHTML = "An unknown error occurred."
break;
}
}
</script>
</body>
</html>
</apex:page>
Hi, Now it is working like, On click of checkin and checkout it is displaying the current location in the map. Also latitude and longitude are stored in latlong variable. However i also want to display the current location's physical address. Please help me out.
Thanks
<script src="http://www.google.com/jsapi?key=ABQIAAAAlJFc1lrstqhgTl3ZYo38bBQcfCcww1WgMTxEFsdaTsnOXOVOUhTplLhHcmgnaY0u87hQyd-n-kiOqQ"></script>
<script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<html>
<body>
<p id="demo">Click the button to get your position.</p>
<button onclick="getLocation()">Check-In</button>
<div id="mapholder"></div>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, showError);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
alert('some');
var latlon = position.coords.latitude + "," + position.coords.longitude;
var img_url = "http://maps.googleapis.com/maps/api/staticmap?center="
+latlon+"&zoom=14&size=400x300&sensor=false";
document.getElementById("mapholder").innerHTML = "<img src='"+img_url+"'>";
}
function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
x.innerHTML = "User denied the request for Geolocation."
break;
case error.POSITION_UNAVAILABLE:
x.innerHTML = "Location information is unavailable."
break;
case error.TIMEOUT:
x.innerHTML = "The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
x.innerHTML = "An unknown error occurred."
break;
}
}
</script>
<p id="demo1">Click the button to get your position.</p>
<button onclick="getLocation1()">Check-Out</button>
<div id="mapholder1"></div>
<script>
function getLocation1() {
var x1 = document.getElementById("demo1");
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition1, showError1);
} else {
x1.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition1(position) {
alert('here');
var latlon1 = position.coords.latitude + "," + position.coords.longitude;
var img_url1 = "http://maps.googleapis.com/maps/api/staticmap?center="
+latlon1+"&zoom=14&size=400x300&sensor=false";
document.getElementById("mapholder1").innerHTML = "<img src='"+img_url1+"'>";
}
function showError1(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
x1.innerHTML = "User denied the request for Geolocation."
break;
case error.POSITION_UNAVAILABLE:
x1.innerHTML = "Location information is unavailable."
break;
case error.TIMEOUT:
x1.innerHTML = "The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
x1.innerHTML = "An unknown error occurred."
break;
}
}
</script>
</body>
</html>
</apex:page>
Hi, Now it is working like, On click of checkin and checkout it is displaying the current location in the map. Also latitude and longitude are stored in latlong variable. However i also want to display the current location's physical address. Please help me out.
Thanks