Reputation: 106
My device is a HTC One X, browser is Chrome. I'm trying to get HTML5 GeoLocation to work in browser however I'm unable to, it works on iOS and desktop however nothing for my Android. Below is my code:
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
<meta content='width=device-width, initial-scale=1, maximum-scale=1' name='viewport'>
<title>HTML5 Test</title>
<script src='http://cloud.keepiteasy.net/libs/modernizr.custom.89661.js' type='text/javascript'></script>
<script src='http://cloud.keepiteasy.net/libs/jquery.js' type='text/javascript'></script>
</meta>
</head>
<body>
<script type="text/javascript">
$(function() {
if (Modernizr.geolocation) {
navigator.geolocation.getCurrentPosition(success, error);
}
function success(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
alert(lat);
alert(lng);
}
function error(err) {
if(err.code == 1) {
alert("Error: Access is denied!");
}else if( err.code == 2) {
alert("Error: Position is unavailable!");
}
}
});
</script>
</body>
</html>
UPDATE: I fixed the doctype UPDATE: I updated the error function UPDATE: On my HTC I am still getting nothing, not even an error. On my Nexus 7 (just tried it), it works fine... WTF, hardware issue? But other GPS based apps work...
Upvotes: 1
Views: 5365
Reputation: 5727
Just restart your phone, guys. Yeah it's kinda stupid but it's the solution.
Upvotes: 1
Reputation: 31
I got the same issue on my HTC One X. At least you can make sure, your error function gets called, by adding a timeout:
navigator.geolocation.getCurrentPosition(success, error, {timeout:3000});
In this example, your error function gets called after 3 seconds.
Upvotes: 3
Reputation: 106
Seems to be a hardware issue of some sort as no website can acquire my geolocation on my OneX, however my Nexus 7 the above code works fine.
Upvotes: 1