1

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...

7
  • 1
    Seems a little odd to use an XHTML doctype when you're trying to do HTML5 stuff :-) Commented Feb 10, 2013 at 22:26
  • Your code works for me on my HTC One X here but that's an HTML5 doctype ... 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) Commented Feb 10, 2013 at 22:35
  • trying this now, also changed to an html5 doc type Commented Feb 10, 2013 at 22:40
  • Did you ever get this to work on your HTC? Would love to know how! Commented Apr 19, 2013 at 20:58

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

1

Just restart your phone, guys. Yeah it's kinda stupid but it's the solution.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.