我正在使用 JavaScript、HTML、CSS 制作谷歌浏览器扩展。为此,我需要读取用户提供的地址的经度和纬度。在测试我的扩展时,我一直在错误以下
这是我的js代码
result: {
data: function (from, to, hrs, mins) {
fromaddress = from;
toaddress = to;
hours = hrs;
minutes = mins;
View.result.readLatLng();
},
readLatLng: function () {
//var addressone = document.getElementById("addressone").value;
geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': fromaddress}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latitude = results[0].geometry.location.latitude;
var longitude = results[0].geometry.location.longitude;
console.log('lat: ' + latitude + ', lng: ' + longitude);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
}
这是我的 manifest.json 文件
{
"name": "Name",
"version": "1.0",
"manifest_version": 2,
"background": {
"scripts": [
"js/result.js",
"js/script.js"
]
},
"description": "Desc",
"browser_action": {
"default_icon": "images/icon.png",
"default_title": "Title",
"default_popup": "html/popup.html"
},
"permissions": [
"http://*/",
"https://maps.google.com/*",
"https://maps.googleapis.com/*",
"http://localhost/*",
"geolocation"
],
"content_security_policy": "script-src 'self' https://maps.googleapis.com https://maps.gstatic.com; object-src 'self'"
}
请帮助我如何解决这个问题?