首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Yandex地图-获取交通数据

Yandex地图-获取交通数据
EN

Stack Overflow用户
提问于 2015-02-04 07:21:51
回答 1查看 2.6K关注 0票数 1

我试着用yandex地图在特定的时间和地点获取交通数据。我看此页( yandex地图的api )。我可以在我自己的地图上显示交通数据。使用地理编码,从yandex地图中提取一些数据(地名、坐标等)。但我不知道怎么才能提取流量数据。我该怎么做呢?yandex地图api有什么功能吗?

我在地图上显示交通数据的简单代码如下

代码语言:javascript
复制
ymaps.ready(init);
    var myMap, 
        myPlacemark;

    function init(){ 
        myMap = new ymaps.Map ("mapId", {
            center: [28.968484, 41.01771],
            zoom: 7
        }); 

        myPlacemark = new ymaps.Placemark([28.968484, 41.01771], {
            content: 'Moscow!',
            balloonContent: 'Capital of Russia'
        });                     


        // This page should show traffic and the "search on map" tool
        ymaps.load(['package.traffic', 'package.search'], addControls);

        myMap.geoObjects.add(myPlacemark);
    }       

    function addControls(map) {
        myMap.controls.add('trafficControl').add('searchControl');
        var trafficControl = new ymaps.control.TrafficControl({shown: true});
        map.controls.add(trafficControl);
        function updateProvider () {
             trafficControl.getProvider('traffic#actual').update();  
        }
        // We will send a request to update data every 4 minutes.
        window.setInterval(updateProvider, 1 * 60 * 1000);
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-04 10:26:09

没有合法的方法可以做到这一点。在论坛上有一些注释,人们使用Yandex地图的内部api,但据我所知,他们被Yandex团队迅速禁止。Yandex不提供任何与地图分离的交通数据。我建议你看一看谷歌地图Api,你可以在你指定的路线上获得交通信息。示例:

代码语言:javascript
复制
    final String baseUrl = "http://maps.googleapis.com/maps/api/directions/json";// path to Geocoding API via http

    final Map<String, String> params = new HashMap<String, String>();
    params.put("sensor", "false");// if data for geocoding comes from device with sensor
    params.put("language", "en");
    params.put("mode", "driving");// move mode, could be driving, walking, bicycling
    params.put("origin", "Russia, Moscow, Poklonnaya str., 12");// start point of route as address or text value of lon and lat
    params.put("destination", "Russia, Moscow, metro station Park Pobedy");// the same for end point
    final String url = baseUrl + '?' + encodeParams(params);// generate final url

    final JSONObject response = JsonReader.read(url);// perform request and read answer where we could also get coordinates
    //results[0]/geometry/location/lng and results[0]/geometry/location/lat

    JSONObject location = response.getJSONArray("routes").getJSONObject(0);
    location = location.getJSONArray("legs").getJSONObject(0);
    final String distance = location.getJSONObject("distance").getString("text"); // get distance for route
    final String duration = location.getJSONObject("duration").getString("text"); // get duration for route

要获得更多信息,只需查看一下https://developers.google.com/maps/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28315678

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档