[英]Google maps js api working on browser but not on cordova app
[英]Google Maps JS API Windows Phone Cordova
因此,我正在嘗試制作使用Google Maps API的應用。 它適用於Android,但當我在Windows Phone模擬器上嘗試它時,它說“一個應用程序無法加載本地上下文中的遠程Web內容”。 現在,我搜索了一下,這是預期的(我也嘗試過使用iframe
的解決方案 - 沒有用。)。 問題是如何解決這個問題。是否可以將谷歌地圖用於Windows Phone和Cordova,或者我必須使用不同的Maps API?
適用於Android但不適用於WP的代碼: - 謝謝大家。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Security-Policy" content=" ">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>BlankCordovaApp1</title>
<!-- BlankCordovaApp1 references -->
<link href="css/index.css" rel="stylesheet" />
<link href="css/jquery.mobile-1.4.5.css" rel="stylesheet" />
<script src="scripts/jquery-2.1.4.js"></script>
<script src="scripts/jquery.mobile-1.4.5.js"></script>
<script>
$(document).on("pagecreate","#map-page", getMaps);
function createMap() {
console.log("Reached createMap() ")
var mapOptions = {
center: new google.maps.LatLng(37.98392, 23.71889),
zoom: 11
};
var map = new google.maps.Map(document.getElementById('map'), mapOptions);
}
function getMaps() {
$.getScript('http://maps.googleapis.com/maps/api/js?callback=createMap');
console.log("Got Maps");
}
</script>
</head>
<body>
<!--Page 1-->
<div data-role="page" id="login" data-theme="b">
<div data-role="content">
<p>Page 1</p>
<a href="#map-page" class="ui-btn">Page 2</a>
</div>
</div>
<!--Page 2-->
<div data-role="page" id="map-page">
<div data-role="header">
<h1> Header </h1>
</div>
<div data-role="content">
<div id="map" style="height: 400px;width: 100%"></div>
<a href="#" class="ui-btn" data-rel="back">Go Back</a>
</div>
<div data-role="footer" style="text-align:center" data-position="fixed">
<p> Footer </p>
</div>
</div>
<!-- Cordova reference, this is added to your app when it's built. -->
<script src="cordova.js"></script>
<script src="scripts/platformOverrides.js"></script>
<script src="scripts/index.js"></script>
</body>
</html>
確保您在Manifest文件中具有正確的功能。 我不做Windows phpne 8,但大多數時候你的應用程序需要從用戶預先允許訪問互聯網。
Properties/WPAppManifest.xml
<Capabilities>
<Capability Name="ID_CAP_NETWORKING" />
</Capabilities>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.