Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

The below code works in Firefox but not in Google Chrome:

<!DOCTYPE html>
<html>
    <head>
        <title>title</title>
        <script type="text/javascript">
            var successCallback = function(data) {
                console.log('latitude: ' + data.coords.latitude + ' longitude: ' + data.coords.longitude);
            };

            var failureCallback = function() {
                console.log('location failure :(');
            };

            var logLocation = function() {

                //determine if the handset has client side geo location capabilities
                if(navigator.geolocation){
                   navigator.geolocation.getCurrentPosition(successCallback, failureCallback);
                }
                else{
                   alert("Functionality not available");
                }
            };

            logLocation();
            setTimeout(logLocation, 5000);
        </script>
    </head>
    <body>
        <p>Testing</p>
    <body>
</html>

What's going on? I thought Google Chrome was supposed to support the W3C Geolocation API.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
342 views
Welcome To Ask or Share your Answers For Others

1 Answer

Works perfectly for me - with both Chrome 11 and Firefox 4.0.1 on Win 7

  • Make sure you've not disabled location tracking in Chrome: Options > Under the Hood > Content Settings > Location
  • Because of security restrictions, resources loaded with the file:/// scheme are not allowed access to location. See HTML 5 Geo Location Prompt in Chrome.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...