Chrome中的HTML 5地理位置提示 [英] HTML 5 Geo Location Prompt in Chrome
问题描述
我正在使用的脚本:
< script type =text / javascriptJavaScriptSRC =geo.js>< / script>
< script type =text / javascript JavaScriptSRC =Utility.js>< / script>
< script type =text / javascriptJavaScriptSRC =jquery.js>< / script>
< script type =text / javascriptJavaScriptSRC =modernizr的.js>< /脚本>
函数get_location(){
if(geo_position_js.init()){
geo_position_js.getCurrentPosition(show_map,handle_error);
}
}
函数show_map(位置){
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
alert(lat:+ latitude +long:+ longitude);
}
函数handle_error(err){
alert(err.code);
if(err.code == 1){
//用户说不!
}
}
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(show_map,handle_error);
} else {
error('not supported');
}
我正在测试我的机器上的本地目录,所以没有真的不像http://whatever.com/mytestpage.html这样的域名。这是为什么我没有得到提示?如果是这样,是否有可能强制browswer请求获取用户地理位置的权限,并可以在我的场景中使用?
/ URI,但不幸的是,它似乎没有记录任何错误来表明这一点。它将从本地Web服务器上运行。如果您安装了python,请尝试在测试文件所在的目录中打开命令提示符并发出以下命令:
python -m SimpleHTTPServer
它应该在端口8000上启动一个web服务器(可能是别的,但它会在控制台告诉你它正在监听的端口),然后浏览到 http:// localhost:8000 / mytestpage.html 如果您没有python,那么Ruby中有相应的模块,或者Visual Web Developer Express附带内置的本地Web服务器。 Just starting to get into HTML 5 and an testing out geo location...liking it so far. I am hitting a bit of a speed bump though...when I try to get my geo location, chrome automatically blocks the page from getting my location. This does not happen at other sites such as the site below: The scripts I'm using: I am testing this out from a local directory on my machine, so there isn't really a "domain" like "http://whatever.com/mytestpage.html". Is this why I am not getting prompted? If so, is it possible to force the browswer to request permission to get the user's geo location and is it possible in my scenario? There's some sort of security restriction in place in Chrome for using geolocation from a It should start up a web server on port 8000 (might be something else, but it'll tell you in the console what port it's listening on), then browse to http://localhost:8000/mytestpage.html If you don't have python there are equivalent modules in Ruby, or Visual Web Developer Express comes with a built in local web server. 这篇关于Chrome中的HTML 5地理位置提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
<script type="text/javascript" JavaScript" SRC="geo.js"></script>
<script type="text/javascript" JavaScript" SRC="Utility.js"></script>
<script type="text/javascript" JavaScript" SRC="jquery.js"></script>
<script type="text/javascript" JavaScript" SRC="modernizr.js"></script>
function get_location() {
if (geo_position_js.init()) {
geo_position_js.getCurrentPosition(show_map, handle_error);
}
}
function show_map(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
alert("lat:" + latitude + " long:" + longitude);
}
function handle_error(err) {
alert(err.code);
if (err.code == 1) {
// user said no!
}
}
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(show_map, handle_error);
} else {
error('not supported');
}
file:///
URI, though unfortunately it doesn't seem to record any errors to indicate that. It will work from a local web server. If you have python installed try opening a command prompt in the directory where your test files are and issuing the command:python -m SimpleHTTPServer