这里的测地折线

时间:2018-08-27 01:36:58

标签: javascript api here-api

许多代码中我都试图从Google Maps切换到Here。让我烦恼的一件事是需要测地线而不是“直线”

可以在这里找到一个示例:http://www.2timothy42.org/Travel/?Mode=

还有另一个答案为here的StackOverflow问题,但该链接不再起作用。

感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

示例的域已更改,但可在此处使用:https://tcs.ext.here.com/examples/v3/geodesic_polyline

答案 1 :(得分:1)

HERE开发人员支持发布的示例可以使您到达那里,但是代码中没有多余的内容,并且还包含一些相对的JS引用,一旦输入我的代码就无法使用。

这与我注意到的Google Maps API和HERE API的主要区别之一是Google Maps使用一个JS调用,因为这里有几个JS调用,如果未正确包含它们,则会产生一些问题。

<meta name="viewport" content="initial-scale=1.0, width=device-width" />
<link rel="stylesheet" type="text/css" href="https://js.api.here.com/v3/3.0/mapsjs-ui.css?dp-version=1533195059" />
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-core.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-service.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-ui.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-mapevents.js"></script>       
<script src="https://tcs.ext.here.com/assets/geodesic-polyline-955f4bde9d216d0e89b88f4ba29c75fd1407f30f905380039e312976f3e30c88.js"></script>

身体

<div id="map" style='width: 600px; height: 300px; border: 1px solid #000000;'></div>
<script  type="text/javascript" charset="UTF-8" >

    // Check whether the environment should use hi-res maps
    var hidpi = ('devicePixelRatio' in window && devicePixelRatio > 1);

    // check if the site was loaded via secure connection
    var secure = (location.protocol === 'https:') ? true : false;

    // Create a platform object to communicate with the HERE REST APIs
    var platform = new H.service.Platform({
        useCIT: true,
        useHTTPS: secure,
        app_id: 'API_APP_ID',
        app_code: 'API_APP_CODE'
    }),
    maptypes = platform.createDefaultLayers(hidpi ? 512 : 256, hidpi ? 320 : null);

    // Instantiate a map in the 'map' div, set the base map to normal
    var map = new H.Map(document.getElementById('map'), maptypes.normal.map, {
        center: {lat:32.00, lng:-110.00}, 
        zoom: 1,                
        pixelRatio: hidpi ? 2 : 1
    });

    // Enable the map event system
    var mapevents = new H.mapevents.MapEvents(map);

    // Enable map interaction (pan, zoom, pinch-to-zoom)
    var behavior = new H.mapevents.Behavior(mapevents);

    // Enable the default UI
    var ui = H.ui.UI.createDefault(map, maptypes);

    window.addEventListener('resize', function() { map.getViewPort().resize(); });
    var npoints = 100, 
        offset = 20;

    // Tokyo -> san Francisco
    add([35.68019,139.81194],[37.77712,-122.41964], {style: { strokeColor: "rgba(0,0,255,0.7)", lineWidth: 4}});

    function add(s,e,options) {
        var start_ll = new H.geo.Point(s[0],s[1]),
            end_ll = new H.geo.Point(e[0],e[1]),
            start_coord = {x: start_ll.lng, y:start_ll.lat},
            end_coord = {x:end_ll.lng, y:end_ll.lat};
            description = ''+s[0]+','+s[1]+'=>'+e[0]+','+e[1]+'',
            gc0 = new arc.GreatCircle(start_coord,end_coord, {'name': 'line', 'color':'#ff7200','description':description}),
            line0 = gc0.Arc(npoints,{offset:offset}),
            strip = line0.strip();

        map.addObject(new H.map.Polyline(strip, options));
    }
</script>