2017-08-17 53 views
0

对于我的Chrome扩展,我试图显示用户的位置。我的js代码是如下如何在Chrome扩展上显示用户位置?

document.addEventListener("DOMContentLoaded",function(loc){ 
    var x = document.getElementById(demo); 
    getLocation(); 


}); 
function getLocation() { 
    if (navigator.geolocation) { 
     navigator.geolocation.getCurrentPosition(showPosition); 
    } else { 
     x.innerHTML = "Geolocation is not supported by this browser."; 
    } 
} 

function showPosition(position) { 
    x.innerHTML = "Latitude: " + position.coords.latitude + 
    "<br>Longitude: " + position.coords.longitude; 
} 

而且在mainfest.json

"permissions": [ 
"tabs", "<all_urls>", 
"geolocation" 

]

添加权限,但它不显示任何内容。请指教我。

+0

您是否接受chrome访问您当前的位置? – user8256287

+0

上面的代码适合我。 – user8256287

+0

可以请你告诉如何接受铬访问位置? – user13107

回答