i have page with button, when clicked shows an alert with latitude and longitude. It works on Chrome on my laptop but when i tried with my android mobile, the page is showing but the alert is not. I have tried changing watchPosition with getCurrentPosition, but no change.
In an attempt to solve it, i have put up an alert checkpoint and i have found out that the function success() is getting called in laptop browser but not in android browser, not even the function error() is being called.
please help.
<html>
<head><title>Geolocation</title></head>
<body onload="getLocation();">
<input type="button" id="btnSearch" value="Search" onclick="btn_Click();"/>
<script>
var pos;
function btn_Click() {
alert("Alert");
//alert('Lat: ' + pos.coords.latitude + ' ' + 'Lon: ' + pos.coords.longitude);
}
function getLocation() {
alert("doSomething");
if (navigator.geolocation) {
alert("navigator.geolocation");
navigator.geolocation.getCurrentPosition(success,error,options);
function success(position) {
alert("success");
pos = position;
}
function error(err) {
alert("Error");
};
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
} else {
alert("I'm sorry, but geolocation services are not supported by your browser.");
}
}
</script>
</body>
</html>
i have even tried google gears, Now the gps sign is coming up on android but the location is still not showing....
<html>
<head><title>Javascript geo sample</title>
<script src="geo-min.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<b>Javascript geo sample</b>
<script>
var pos;
if (geo_position_js.init()) {
geo_position_js.watchPosition(success_callback, error_callback, { enableHighAccuracy: true });
}
else {
alert("Functionality not available");
}
function success_callback(p) {
pos = p;
alert('lat=' + p.coords.latitude.toFixed(2) + ';lon=' + p.coords.longitude.toFixed(2));
}
function error_callback(p) {
alert('error=' + p.message);
}
function ChangeLabel() {
document.getElementById("Label1").innerHTML =pos.coords.latitude;
}
</script>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
<input type="button" ID="Button1" value="Button" onclick="ChangeLabel()"/>
</body>
</html>