1

我正在尝试将 nokia here 地图嵌入到 android webview 中,并且工作得很好。问题在于标记单击侦听器:如果我在浏览器中打开 html 文件,侦听器会触发,但不会在我的 android web 视图中。我确定在 web 视图中正确配置了 javascript 事件,因为如果我使用 html 按钮,onclick 可以工作。

这是hml页面

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=7; IE=EmulateIE9; IE=10" />
<base
    href="http://developer.here.com/apiexplorer/examples/api-for-js/markers/marker.html" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Nokia Maps API for JavaScript Example: Adding a marker</title>
<meta name="description"
    content="Putting a standard marker onto the map" />
<meta name="keywords" content="standardmarker, map objects, markers" />
<!-- For scaling content for mobile devices, setting the viewport to the width of the device-->
<meta name=viewport
    content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<!-- Styling for example container (NoteContainer & Logger)  -->
<link rel="stylesheet" type="text/css"
    href="http://developer.here.com/apiexplorer/examples/templates/js/exampleHelpers.css" />
<!-- By default we add ?with=all to load every package available, it's better to change this parameter to your use case. Options ?with=maps|positioning|places|placesdata|directions|datarendering|all -->
<script type="text/javascript" charset="UTF-8"
    src="http://js.cit.api.here.com/se/2.5.3/jsl.js?with=maps"></script>
<!-- JavaScript for example container (NoteContainer & Logger)  -->
<script type="text/javascript" charset="UTF-8"
    src="http://developer.here.com/apiexplorer/examples/templates/js/exampleHelpers.js"></script>
<style type="text/css">


body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    position: absolute;
}

#mapContainer {
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    position: absolute;
}
</style>
</head>
<body>
    <div id="mapContainer"></div>
    <div id="uiContainer"></div>


    <script type="text/javascript" id="exampleJsSource">
        /*  Setup authentication app_id and app_code 
         *  WARNING: this is a demo-only key
         *  please register for an Evaluation, Base or Commercial key for use in your app.
         *  Just visit http://developer.here.com/get-started for more details. Thank you!
         */


        nokia.Settings.set("app_id", "DemoAppId01082013GAL");
        nokia.Settings.set("app_code", "AJKnXv84fjrb0KIHawS0Tg");
        // Use staging environment (remove the line for production environment)
        nokia.Settings.set("serviceMode", "cit");

        // Get the DOM node to which we will append the map
        var mapContainer = document.getElementById("mapContainer");
        // Create a map inside the map container DOM node
        var map = new nokia.maps.map.Display(mapContainer, {
            // Initial center and zoom level of the map
            center : [ 52.51, 13.4 ],
            zoomLevel : 10,
            // We add the behavior component to allow panning / zooming of the map
            components : [ new nokia.maps.map.component.Behavior() ]
        });

        var fernsehturmMarker = new nokia.maps.map.StandardMarker(
                new nokia.maps.geo.Coordinate(52.520816, 13.409417), {
                    title : 'This has a click event',
                    brush : {
                        color : '#00AA00'
                    }
                });
        fernsehturmMarker.addListener('click', function(evt) {
            //$('.loc').html(times[i]); 
            alert('');
        });
        /* Create a marker on a specified geo coordinate 
         * (in this example we use the map's center as our coordinate)
         */
        //var standardMarker = new nokia.maps.map.StandardMarker(map.center);
        // Next we need to add it to the map's object collection so it will be rendered onto the map.
        map.objects.add(fernsehturmMarker);


    </script>
</body>
</html>

这是我在 onCreate 方法中的 java 代码

nokiaMap = (NoZoomControllWebView) getActivity().findViewById(R.tab_map_nokia.webView);
nokiaMap.getSettings().setJavaScriptEnabled(true);
nokiaMap.getSettings().setDomStorageEnabled(true);
nokiaMap.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
nokiaMap.getSettings().setSupportMultipleWindows(true);
nokiaMap.setWebChromeClient(new WebChromeClient() );
nokiaMap.loadUrl("file:///android_asset/marker.html");

有人有同样的问题吗?

4

1 回答 1

0

刚刚遇到这个开放的话题。您知道 HERE 同时为 Android 和 iOS 提供 SDK 吗?

更多信息可以在这里找到: https ://developer.here.com/develop/mobile-sdks

这可能比嵌入 JavaScript API 更容易。

于 2018-11-14T08:15:41.833 回答