:) 我尝试在这里集成地图javascript api并按照HERE地图网站https://developer.here.com/api-explorer中的示例进行操作。然后我使用Web预览和Worklight中的MBS测试它,结果如预期(Map正确显示)。但是当我在Android移动设备上看到结果时,地图不会显示。
我该如何解决这个问题?
这是我的index.html和main.js文件:
main.js:
var map;
function wlCommonInit(){
if(WL.Environment.PREVIEW != WL.Client.getEnvironment()){
console.log("Used Cordova version is: " + device.cordova);
}
//Step 1: initialize communication with the platform
var platform = new H.service.Platform({
app_id: 'DemoAppId01082013GAL',
app_code: 'AJKnXv84fjrb0KIHawS0Tg',
useCIT: true,
useHTTPS: true
});
var defaultLayers = platform.createDefaultLayers();
//Step 2: initialize a map - not specificing a location will give a whole world view.
map = new H.Map(document.getElementById('map'),
defaultLayers.normal.map);
//Step 3: make the map interactive
// MapEvents enables the event system
// Behavior implements default interactions for pan/zoom (also on mobile touch environments)
var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));
// Create the default UI components
var ui = H.ui.UI.createDefault(map, defaultLayers);
}
function moveMapToBerlin(){
map.setCenter({lat:52.5159, lng:13.3777});
map.setZoom(14);
}
的index.html:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>HereMapApp</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
<!--
<link rel="shortcut icon" href="images/favicon.png">
<link rel="apple-touch-icon" href="images/apple-touch-icon.png">
-->
<link rel="stylesheet" href="css/main.css">
<script>window.$ = window.jQuery = WLJQ;</script>
<link rel="stylesheet" type="text/css" href="https://js.api.here.com/v3/3.0/mapsjs-ui.css" />
<script type="text/javascript" charset="UTF-8" src="https://js.api.here.com/v3/3.0/mapsjs-core.js"></script>
<script type="text/javascript" charset="UTF-8" src="https://js.api.here.com/v3/3.0/mapsjs-service.js"></script>
<script type="text/javascript" charset="UTF-8" src="https://js.api.here.com/v3/3.0/mapsjs-ui.js"></script>
<script type="text/javascript" charset="UTF-8" src="https://js.api.here.com/v3/3.0/mapsjs-mapevents.js"></script>
</head>
<body style="display: none;">
<button onclick="moveMapToBerlin();">map</button>
<div id="map" style="width: 100%; height: 400px; background: grey"></div>
<script src="js/initOptions.js"></script>
<script src="js/main.js"></script>
<script src="js/messages.js"></script>
</body>
</html>
更新 我在这里附加来自logcat的完整日志文件:http://pastebin.com/KN1GFMYZ
12-01 15:18:39.945: D/CordovaActivity(28650): onMessage(spinner,stop)
12-01 15:18:39.953: D/CordovaNetworkManager(28650): Connection Type: wifi
12-01 15:18:39.956: D/CordovaNetworkManager(28650): Connection Type: wifi
12-01 15:18:39.956: D/CordovaActivity(28650): onMessage(networkconnection,wifi)
12-01 15:18:39.990: D/CordovaLog(28650): : Line 0 : Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.
12-01 15:18:39.990: I/chromium(28650): [INFO:CONSOLE(0)] "Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.", source: (0)
12-01 15:18:40.018: D/CordovaWebViewClient(28650): onPageFinished(file:///android_asset/www/default/index.html)
12-01 15:18:40.018: D/CordovaActivity(28650): onMessage(onPageFinished,file:///android_asset/www/default/index.html)
12-01 15:18:40.233: W/PluginManager(28650): THREAD WARNING: exec() call to DeviceAuth.getDeviceUUID blocked the main thread for 174ms. Plugin should use CordovaInterface.getThreadPool().
12-01 15:18:40.262: D/CordovaLog(28650): file:///android_asset/www/default/js/main.js: Line 6 : Used Cordova version is: 3.4.0
12-01 15:18:40.262: I/chromium(28650): [INFO:CONSOLE(6)] "Used Cordova version is: 3.4.0", source: file:///android_asset/www/default/js/main.js (6)
12-01 15:18:40.464: D/CordovaLog(28650): file:///android_asset/www/default/js/main.js: Line 46 : Used Android Cordova version is: 3.4.0
12-01 15:18:40.464: I/chromium(28650): [INFO:CONSOLE(46)] "Used Android Cordova version is: 3.4.0", source: file:///android_asset/www/default/js/main.js (46)
12-01 15:18:40.538: D/NONE(28650): ondeviceready event dispatched
12-01 15:18:40.540: D/NONE(28650): wlclient init started
12-01 15:18:40.542: D/NONE(28650): Read cookies: null
12-01 15:18:40.545: W/NONE(28650): Note that if your application targets Android 3.0 (API level 11) or higher, WL.OptionsMenu might have no effect, depending on the device.
12-01 15:18:40.548: D/NONE(28650): CookieMgr read cookies: {}
12-01 15:18:40.551: D/NONE(28650): after: initOptions.onSuccess
12-01 15:18:40.553: D/NONE(28650): added onPause event handler
12-01 15:18:40.555: D/NONE(28650): before: initOptions.onSuccess
12-01 15:18:40.559: D/NONE(28650): wlclient init success
12-01 15:18:40.731: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///bbbb0428-df73-4c7e-a969-f8ea45913234
12-01 15:18:40.734: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///e0194112-fd69-45c9-a34f-f7ffef324a68
12-01 15:18:40.955: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///6814f68e-33da-4012-8442-d1042f89ae7a
12-01 15:18:41.123: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///c7528252-cf1b-4568-98a9-95adc55ddde5
12-01 15:18:41.361: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///1fca0729-a44f-408b-8162-5a37a9bf5b6f
12-01 15:18:41.566: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///555a087f-be43-4bea-b2c0-84332c0e30cd
12-01 15:18:44.754: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///10b8291c-5b81-4530-a8c4-44cfd39bb659
12-01 15:18:44.770: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///b3c6d0d4-a179-47d4-8d91-ed8f6bb05182
12-01 15:18:44.778: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///8ff79fe1-457a-44ee-821f-6ac4d538e34b
12-01 15:18:44.780: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///4ea403d6-6a04-4336-b38f-44768416733e
12-01 15:18:44.782: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///792806d2-0eda-4a72-a35a-28c7a16aaab2
12-01 15:18:44.784: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///d325460d-9335-4a6f-bc76-9bf15252eefa
12-01 15:18:44.978: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///03d72c4c-b835-444f-8cea-08c268b8df0a
12-01 15:18:44.998: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///a06ddf31-8d0d-497b-9014-0b50e5594b32
12-01 15:18:45.059: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///9c61eaa2-51a3-48c8-a0e2-6964cc11c642
12-01 15:18:45.066: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///ee88dbe1-ff90-4eba-abd2-69844b8da755
12-01 15:18:45.076: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///0b177836-c385-4bc2-b270-33dcfcc066be
12-01 15:18:45.081: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///387075ce-8fdc-4810-aeaf-94913041bee0
12-01 15:18:45.275: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///1c44ac9b-caca-4fe8-8e6e-7bcc7bd2a65f
12-01 15:18:45.322: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///11e6def0-8b7b-4f24-b5a6-9ca886ef1aae
12-01 15:18:45.328: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///6b10848e-459e-4eb2-935c-f20b9201f262
12-01 15:18:45.332: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///ce08378e-dc05-4b45-8f01-9f1cc16bea80
12-01 15:18:45.337: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///7fdabe92-35a3-4fe7-991d-998fde206247
12-01 15:18:45.341: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///862be287-ee88-4ae8-a0b1-15d6942ef674
12-01 15:18:45.597: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///e5cbcb70-8c13-4d5d-bc9a-11b411ee6eae
12-01 15:18:45.604: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///b71ab981-ba05-4123-9173-b0ac823e3714
12-01 15:18:45.612: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///45450213-10f8-42d5-86cb-a08345739fa0
12-01 15:18:45.618: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///8d704eb2-c8f7-49ed-8065-b04467f5dfda
12-01 15:18:45.625: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///e423d272-470b-4688-9976-7f2f12f8cdb9
12-01 15:18:45.633: W/IceCreamCordovaWebViewClient(28650): URL blocked by whitelist: blob:file%3A///706dcb3e-33d6-4c5d-a7cc-67adc6eb26be
12-01 15:19:45.209: D/CordovaActivity(28650): Paused the application!
12-01 15:19:45.209: D/CordovaWebView(28650): Handle the pause
12-01 15:19:45.211: D/WLClient(28650): WLClient$ActivityListener.onActivityPaused in WLClient.java:1215 :: on activity paused com.HereMapApp.HereMapApp . activity count = 0
12-01 15:19:45.227: D/NONE(28650): Flush called
12-01 15:19:45.249: D/WLClient(28650): WLClient$ActivityListener.onActivitySaveInstanceState in WLClient.java:1227 :: on activity save instance state com.HereMapApp.HereMapApp
12-01 15:19:45.251: D/WLClient(28650): WLClient$ActivityListener.onActivityStopped in WLClient.java:1239 :: on activity stopped com.HereMapApp.HereMapApp
更新 这是我的android cordova config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<widget xmlns = "http://www.w3.org/ns/widgets"
id = "HereMapApp"
version = "1.0.0.0">
<name>HereMapApp</name>
<description>
HereMapApp
</description>
<author href="http://mycompany.com" email="application author's e-mail">
application's author
</author>
<access origin="*"/>
<preference name="loglevel" value="DEBUG" />
<!--
<preference name="splashscreen" value="resourceName" />
<preference name="backgroundColor" value="0xFFF" />
<preference name="loadUrlTimeoutValue" value="20000" />
<preference name="InAppBrowserStorageEnabled" value="true" />
<preference name="disallowOverscroll" value="true" />
-->
<!-- This is required for native Android hooks -->
<feature name="App">
<param name="android-package" value="org.apache.cordova.App" />
</feature>
<feature name="Geolocation">
<param name="android-package" value="org.apache.cordova.geolocation.GeoBroker" />
</feature>
<feature name="Device">
<param name="android-package" value="org.apache.cordova.device.Device" />
</feature>
<feature name="Accelerometer">
<param name="android-package" value="org.apache.cordova.devicemotion.AccelListener" />
</feature>
<feature name="Compass">
<param name="android-package" value="org.apache.cordova.deviceorientation.CompassListener" />
</feature>
<feature name="Media">
<param name="android-package" value="org.apache.cordova.media.AudioHandler" />
</feature>
<feature name="Camera">
<param name="android-package" value="org.apache.cordova.camera.CameraLauncher" />
</feature>
<feature name="Contacts">
<param name="android-package" value="org.apache.cordova.contacts.ContactManager" />
</feature>
<feature name="File">
<param name="android-package" value="org.apache.cordova.file.FileUtils" />
</feature>
<feature name="NetworkStatus">
<param name="android-package" value="org.apache.cordova.networkinformation.NetworkManager" />
</feature>
<feature name="Notification">
<param name="android-package" value="org.apache.cordova.dialogs.Notification" />
</feature>
<feature name="FileTransfer">
<param name="android-package" value="org.apache.cordova.filetransfer.FileTransfer" />
</feature>
<feature name="Capture">
<param name="android-package" value="org.apache.cordova.mediacapture.Capture" />
</feature>
<feature name="Battery">
<param name="android-package" value="org.apache.cordova.batterystatus.BatteryListener" />
</feature>
<feature name="SplashScreen">
<param name="android-package" value="org.apache.cordova.splashscreen.SplashScreen" />
</feature>
<feature name="Globalization">
<param name="android-package" value="org.apache.cordova.globalization.Globalization" />
</feature>
<feature name="InAppBrowser">
<param name="android-package" value="org.apache.cordova.inappbrowser.InAppBrowser" />
</feature>
<feature name="Vibration">
<param name="android-package" value="org.apache.cordova.vibration.Vibration" />
</feature>
<feature name="WLInitializationPlugin">
<param name="android-package" value="com.worklight.androidgap.plugin.WLInitializationPlugin" />
<param name="onload" value="true" />
</feature>
<!-- Due to bug in cordova next feature must set "onload" to false -->
<feature name="UserAuth">
<param name="android-package" value="com.worklight.androidgap.plugin.UserAuthPlugin" />
<param name="onload" value="false" />
</feature>
<feature name="LoggerPlugin">
<param name="android-package" value="com.worklight.androidgap.plugin.LoggerPlugin" />
</feature>
<feature name="WLApp">
<param name="android-package" value="com.worklight.androidgap.plugin.WLApp" />
</feature>
<feature name="NativePage">
<param name="android-package" value="com.worklight.androidgap.plugin.NativePage" />
</feature>
<feature name="NativeBusyIndicator">
<param name="android-package" value="com.worklight.androidgap.plugin.BusyIndicator" />
</feature>
<feature name="SecurityPlugin">
<param name="android-package" value="com.worklight.androidgap.plugin.SecurityPlugin" />
</feature>
<feature name="StoragePlugin">
<param name="android-package" value="com.worklight.androidgap.plugin.StoragePlugin" />
</feature>
<feature name="Push">
<param name="android-package" value="com.worklight.androidgap.plugin.Push" />
</feature>
<feature name="WebResourcesDownloader">
<param name="android-package" value="com.worklight.androidgap.plugin.WebResourcesDownloaderPlugin" />
</feature>
<feature name="NetworkDetector">
<param name="android-package" value="com.worklight.androidgap.plugin.NetworkDetector" />
</feature>
<feature name="DeviceAuth">
<param name="android-package" value="com.worklight.androidgap.plugin.DeviceAuthPlugin" />
</feature>
<feature name="WifiPlugin">
<param name="android-package" value="com.worklight.androidgap.plugin.WifiPlugin" />
</feature>
<feature name="WLGeolocationPlugin">
<param name="android-package" value="com.worklight.androidgap.plugin.WLGeolocationPlugin" />
</feature>
<feature name="ForegroundBinderPlugin">
<param name="android-package" value="com.worklight.androidgap.plugin.ForegroundBinderPlugin" />
</feature>
<feature name="FIPSHttpPlugin">
<param name="android-package" value="com.worklight.androidgap.plugin.FIPSHttpPlugin" />
</feature>
<feature name="WLCustomDialog">
<param name="android-package" value="com.worklight.androidgap.plugin.WLCustomDialog" />
</feature>
<feature name="NetworkStatus">
<param name="android-package" value="com.worklight.androidgap.plugin.WLNetworkManager" />
</feature>
<feature name="WLSplashScreen">
<param name="android-package" value="com.worklight.androidgap.plugin.WLSplashScreenPlugin" />
</feature>
<feature name="WLDirectUpdatePlugin">
<param name="android-package" value="com.worklight.androidgap.plugin.WLDirectUpdatePlugin" />
</feature>
<feature name="WLNativeXHRPlugin">
<param name="android-package" value="com.worklight.androidgap.plugin.WLNativeXHRPlugin" />
</feature>
<feature name="WLActionSenderPlugin">
<param name="android-package" value="com.worklight.androidgap.plugin.WLActionSenderPlugin" />
</feature>
<feature name="WLTrusteer">
<param name="android-package" value="com.worklight.androidgap.plugin.WLTrusteerPlugin" />
</feature>
</widget>
我试图添加<access origin="blob:*" launch-external="true" />
但仍然没有运气,我也尝试添加
<allow-navigation href="*" />
<allow-navigation href="blob:*" />
但结果仍然相同。
请提前帮助我解决这个问题:)
答案 0 :(得分:1)
根据HERE Maps API for JavaScript Developer's Guide,您需要在编写代码时使用自己的app_id
和app_code
。您可以获取一对凭据来测试您的应用here,只需替换以下部分中的代码:
var platform = new H.service.Platform({
app_id: '{YOUR_APP_ID}',
app_code: '{YOUR_APP_CODE}',
useCIT: true,
useHTTPS: true
});
上面代码中使用的DemoAppId01082013GAL
应用ID不会列入白名单以供一般使用。