gpt4 book ai didi

android - Google Maps Javascript API V3 在移动/ native 应用程序上找不到 404

转载 作者:太空狗 更新时间:2023-10-29 16:14:20 24 4
gpt4 key购买 nike

我可以毫无问题地让 Google map 显示在浏览器中。当我使用 phonegap build 打包我的应用程序时,它不起作用。在我的远程调试 session 中,它说

https://maps.googleapis.com/maps/api/js?key=My_Key_Goes_Here 
Failed to load resource: the server responded with a status of 404 (Not Found)

在文档的头部我有:

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=MyKey"></script>
<script src="js/locations.js" type="text/javascript"></script>

在网络控制台中我得到:

Request URL:http://maps.googleapis.com/maps/api/js?key=MyKeyHere
Request Method:GET
Status Code:404 Not Found (from cache)
Response Headers
Client-Via:shouldInterceptRequest
Request Headers
Provisional headers are shown
Accept:*/*
User-Agent:Mozilla/5.0 (Linux; Android 5.0.2; SM-T530NU Build/LRX22G; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/46.0.2490.76 Safari/537.36
Query String Parameters
view source
view URL encoded
key: MyKeyDisplayedHere

在我的 config.xml 文件中,我包含了这些行:

<preference name="orientation" value="portrait" />
<preference name="Fullscreen" value="true" />
<access origin="*://*.googleapis.com/*" subdomains="true" />
<access origin="*://*.gstatic.com/*" subdomains="true" />
<access origin="*://*.google.com/*" subdomains="true" />
<access origin="*://*.googleusercontent.com/*" subdomains="true" />

我使用的是 jQuery Mobile,我没有在第一页上显示 map ,而是在另一页上显示。无论如何,它在尝试从 API 获取时会给出 404,但这是 locations.js 文件中的 JS 代码:

$(document).on('pageshow', "#map-page", function() {
var defaultLatLng = new google.maps.LatLng(34.0983425, -118.3267434); // Default to Hollywood, CA when no geolocation support
if ( navigator.geolocation ) {
function success(pos) {
// Location found, show map with these coordinates
drawMap(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
}
function fail(error) {
drawMap(defaultLatLng); // Failed to find location, show default map
}
// Find the users current position. Cache the location for 5 minutes, timeout after 6 seconds
navigator.geolocation.getCurrentPosition(success, fail, {maximumAge: 500000, enableHighAccuracy:true, timeout: 6000});
} else {
drawMap(defaultLatLng); // No geolocation support, show default map
}
function drawMap(latlng) {
var myOptions = {
zoom: 10,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
console.log('hey');
// Add an overlay to the map of current lat/lng
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: "Greetings!"
});
}
});

我还尝试将 API 的 href 更改为“http”而不是“https”

最佳答案

经过一番挖掘,我发现了一些文档 here:

显然,您必须添加白名单插件而不是原生插件,所以我将 config.xml 文件更改为:

 <access origin="http://*.phonegap.com" subdomains="true" />
<access origin="*://*.googleapis.com/*" subdomains="true" />
<access origin="*://*.gstatic.com/*" subdomains="true" />
<access origin="*://*.google.com/*" subdomains="true" />
<access origin="*://*.googleusercontent.com/*" subdomains="true" />

<plugin name="cordova-plugin-whitelist" />

它现在可以在移动应用程序中使用,我也可以使用我列入白名单的外部资源。

关于android - Google Maps Javascript API V3 在移动/ native 应用程序上找不到 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34272546/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com