2

大家好,我正在创建一个使用 Geolocation API 来定位最终用户的 Web 应用程序。它在我能想到的几乎所有平台上都运行良好,除了 Internet Explorer 9。不过事情变得有点奇怪。如果我将 Google 工具栏加载到我的 Internet Explorer 浏览器窗口中,一切都会顺利进行。这是我一直在使用的有问题的代码块:

if (navigator.geolocation) {
            var locationMarker = null;
            navigator.geolocation.watchPosition(
                function( position ){
                    var point = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);    
                    if (!locationMarker) {
                        locationMarker = addMarker(
                            position.coords.latitude,
                            position.coords.longitude,
                            "Initial Position"
                        );
                    }
                    else{
                        updateMarker(
                            locationMarker,
                            position.coords.latitude,
                            position.coords.longitude,
                            "Updated / Accurate Position"
                        );
                    };
                    map.setCenter(point);
                    if (map.zoom < 17){
                        map.setZoom(17);
                    };
                },
                function( error ){
                    console.log( "Something went wrong: ", error );
                },
                {
                    timeout: (5 * 1000),
                    maximumAge: (1000 * 60 * 15),
                    enableHighAccuracy: true
                }
            );
        }
        else {
            alert("Geolocation is not supported by this browser");
        }

每当我使用 Internet Explorer 9 访问我的应用程序时,我都会收到“此浏览器不支持地理位置”警报。除非我激活了我的 Google 工具栏。但是,如果 Google 工具栏处于活动状态,则 Google 工具栏会处理权限。

如何让地理定位在 IE9 中工作?我的应用程序可以在 Safari、Firefox、Chrome、iOS 和 Android 中完美运行。我完全被难住了。

谢谢,泰勒·沃林

4

1 回答 1

4

user1303379,

IE9 and IE10 both support geolocation, however earlier versions of IE do not support it ( reference http://caniuse.com/#feat=geolocation ). Here is a blog post by IE about geolocation in IE9 http://blogs.msdn.com/b/ie/archive/2011/02/17/w3c-geolocation-api-in-ie9.aspx and here is a test page using navigator.geolocation.watchPosition like you are above.

For browsers that don't support geolocation you may consider using one of the geolocation polyfills listed here https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills

IE9 & IE10 ask the user if they would like to share their location http://cl.ly/image/0X0o2F0s1N03 My guess is that you may have denied access to your location at some point.

The Google Toolbar added a feature to determine geolocation back in the IE8 days http://googletoolbarhelp.blogspot.com/2010/02/google-toolbar-6413211732-for-ie.html From what you describe it sounds like the Google Toolbar started to provide geolocation since the native IE9 geolocation was denied access.

于 2013-01-03T20:39:54.043 回答