我正在开发一个使用 W3C 标准地理定位 API 的应用程序,但我终生无法让它在我的 Windows 7 和 XP PC 上的 Safari 上运行.它在我的 iPad 和 iPhone 上运行良好.它还可以在 Chrome(5、6、7 和 Canary 版本)和 Firefox(3.6)上完美运行.我没有Mac,所以无法对其进行测试.IE 还不支持地理定位,因此也涵盖了这一点.
I am working on an app that uses the W3C standard geolocation API but I cannot for the life of me get it to work on Safari on my Windows 7 and XP PC. It works fine on my iPad and my iPhone. It also works perfect on Chrome (5, 6, 7 and the Canary build) and on Firefox (3.6). I don't have a Mac so I can't test it on that. IE doesn't support geolocation yet so that's covered too.
我创建了一个精简版并将其托管在 Google Apps Engine 上,因此您可以查看代码:http://html5-geolocator.appspot.com/ .所有(简化的)javascript 都在 html 中,因此您应该能够右键单击并调试/查看源代码.
I created a stripped down version and I am hosting it on the Google Apps Engine so you can have a look at the code: http://html5-geolocator.appspot.com/ . All the (simplified) javascript is in the html so you should be able to right-click and debug/view source.
这几乎是 Google 上的示例的直接转换地图 API 开发指南.有趣的是,Google 托管的示例也不适用于 Windows 7 上的 Safari 5.0.x(但它们在所有其他平台上都可以正常工作,与我的应用程序相同),例如 http://code.google.com/apis/maps/documentation/javascript/examples/map-geolocation.html 和我的APP一模一样的问题,没有地图,网页一直是灰色的.
It is pretty much a straight conversion of the examples on the Google Map API DevGuide. Interestingly enough, the examples that Google is hosting are also NOT WORKING in Safari 5.0.x on Windows 7 (but they work fine on all those other platforms, same as my app), for example http://code.google.com/apis/maps/documentation/javascript/examples/map-geolocation.html exhibits exactly the same issue as my APP, no map appears, the webpage just stays grey.
通过一些调试 (alert("I am here") :-) 似乎在 Safari 中,它确实执行了 navigator.geolocation.getCurrentPosition(myCallback),但它似乎永远不会到达 myCallback ...就好像它从来没有从 getCurrentPosition 返回.我还看到,如果我让浏览器窗口在一夜之间打开,当我早上回到它时,警报和地图就会出现(尽管并非总是如此).我还尝试添加了 errorCallback navigator.geolocation.getCurrentPosition(myCallback, errorCallback) 但它也从未执行过,再次表明它永远不会从 getCurrentPosition 调用返回.
Through some debugging (alert("I am here") :-) it seems that in Safari, it does execute navigator.geolocation.getCurrentPosition(myCallback), but it never seems to reach myCallback ... as if it never returns from getCurrentPosition. I have also seen that if I leave the browser window open overnight, when I get back to it in the morning the alert and map have appeared (though not always). I also tried added a errorCallback navigator.geolocation.getCurrentPosition(myCallback, errorCallback) but it also never executes that, again suggesting it never returns from the getCurrentPosition call.
为什么会这样?
只是做了一些更多的测试,我添加了超时选项 (navigator.geolocation.getCurrentPosition(myCallback, errorCallback, {timeout: 5000});) ,事实上它一直超时,不管我设置多高所以它永远不会从 Google 地理定位服务返回,但为什么呢?
Just did some more testing, I added the timeout option (navigator.geolocation.getCurrentPosition(myCallback, errorCallback, {timeout: 5000});) , and indeed it it timing out all the time, no matter how high I set it so it is never returning from the Google geolocation service, but why?
尝试打开你的 wi-fi.看来 Safari 依赖于 wi-fi 连接才能工作.我遇到了完全相同的问题,打开了我的 wi-fi 连接,它运行良好.
Try turning on your wi-fi. It appears that Safari relies on the wi-fi connection to work. I was having exactly the same issues, turned my wi-fi connection on and it work perfectly.
我现在正在研究如何检测这一点 - 如果我找到解决方案会更新
I'm now looking at how to detect this - will update if I find a solution
这篇关于地理定位在 Windows 7/XP 上的 Safari 5.x 上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
Angular 2:在本地 .json 文件中找不到文件Angular 2: file not found on local .json file(Angular 2:在本地 .json 文件中找不到文件)
使用模式 Angular 2 进行输入验证Input validation with pattern Angular 2(使用模式 Angular 2 进行输入验证)
如何在角度2中动态更改css类名How to change the css class name dynamically in angular 2(如何在角度2中动态更改css类名)
如何删除输入类型中的默认颜色?How to remove default color in input type?(如何删除输入类型中的默认颜色?)
如何将点击事件添加到打字稿中动态添加的html元How to add click event to dynamically added html element in typescript(如何将点击事件添加到打字稿中动态添加的html元素)
XPath 具有条件的多个属性值之一XPath one of multiple attribute values with condition(XPath 具有条件的多个属性值之一)