相关疑难解决方法(0)

Chrome中的HTML 5地理位置提示

刚刚开始进入HTML 5和测试地理位置...喜欢它到目前为止.我有点速度碰撞......当我试图获取我的地理位置时,chrome会自动阻止页面获取我的位置.这不会发生在其他网站,如下面的网站:

http://html5demos.com/geo

我正在使用的脚本:

<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');
    }
Run Code Online (Sandbox Code Playgroud)

我正在我的机器上的本地目录中测试这个,所以没有像"http://whatever.com/mytestpage.html"这样的"域名".这是我没有得到提示的原因吗?如果是这样,是否可以强制浏览器请求获取用户地理位置的权限,是否可以在我的方案中使用?

html5 google-chrome geolocation file-uri

68
推荐指数
3
解决办法
9万
查看次数

Google Maps Javascript GeoLocation - 不适用于Chrome

注意:下面引用的html的原始来源来自http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_geolocation_mapGoogle Maps Javascript V3地理位置 - 除非收到警报,否则无法访问initialLocation变量

我收集了三个不同版本的地理位置示例.一切都在Firefox中正常工作.无法在Chrome中使用.我已将Chrome权限设置为允许所有网站使用我的位置,但仍然没有成功.它必须是Chrome设置,但不是显而易见的设置:设置/显示高级设置/隐私/内容设置/位置/允许所有网站跟踪我的实际位置.

在Firefox中,我在提示共享位置后看到我当前的位置.

在Chrome中,我收到用户拒绝地理定位或错误的请求:地理定位服务失败,具体取决于html.

鉴于这适用于Firefox而不是Chrome,我认为它必须是Chrome设置,但我只是不知道我能做什么比允许所有网站跟踪我的物理位置更宽松.

以下是三个HTML5文件:

geoGoogle.html:

<!DOCTYPE html>
<html>
 <head>
   <title>Geolocation</title>
   <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
   <meta charset="utf-8">
   <link href="https://google-developers.appspot.com/maps/documentation/javascript/examples/default.css" rel="stylesheet">
   <!--
   Include the maps javascript with sensor=true because this code is using a
   sensor (a GPS locator) to determine the user's location.
   See: https://developers.google.com/apis/maps/documentation/javascript/basics#SpecifyingSensor
   -->
   <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true"></script>

   <script>
var map;

function initialize() {
 var mapOptions = {
   zoom: 6,
   mapTypeId: google.maps.MapTypeId.ROADMAP
 };
 map = new google.maps.Map(document.getElementById('map-canvas'),
     mapOptions);

 // Try HTML5 geolocation …
Run Code Online (Sandbox Code Playgroud)

html5 google-chrome geolocation

8
推荐指数
1
解决办法
2万
查看次数

标签 统计

geolocation ×2

google-chrome ×2

html5 ×2

file-uri ×1