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='.custom.89661.js' type='text/javascript'></script>
<script src='.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...
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/libs/modernizr.custom.89661.js' type='text/javascript'></script>
<script src='http://cloud.keepiteasy/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...
Share Improve this question edited Feb 10, 2013 at 22:43 Jeff asked Feb 10, 2013 at 22:24 JeffJeff 1061 silver badge10 bronze badges 7- 1 Seems a little odd to use an XHTML doctype when you're trying to do HTML5 stuff :-) – Pointy Commented Feb 10, 2013 at 22:26
- Your code works for me on my HTC One X here but that's an HTML5 doctype ... – Pointy Commented Feb 10, 2013 at 22:28
- Works for me on a Nexus 7 with the broken DOCTYPE. What do you get if you replace the error handler with a real one? e.g. ` function error(err) { if(err.code == 1) { alert("Error: Access is denied!"); }else if( err.code == 2) { alert("Error: Position is unavailable!"); } }` (nicked from here) – Matt Gibson Commented Feb 10, 2013 at 22:35
- trying this now, also changed to an html5 doc type – Jeff Commented Feb 10, 2013 at 22:40
- Did you ever get this to work on your HTC? Would love to know how! – Martijn de Milliano Commented Apr 19, 2013 at 20:58
3 Answers
Reset to default 3I 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.
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.
Just restart your phone, guys. Yeah it's kinda stupid but it's the solution.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745350321a4623793.html
评论列表(0条)