Yandex地图-获取流量数据



我尝试使用yandex地图获取特定时间和地点的交通数据。我看了一下这个页面(yandex地图的api)。我可以在自己的地图上显示交通数据。使用地理编码,我从yandex地图中提取一些数据(地名、坐标等)。但我不知道如何只提取交通数据。我该怎么做?yandex映射api上有什么函数吗?

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

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);
    }

没有合法的方法。论坛上有一些注释,人们使用Yandex地图的内部api,但据我所知,它们很快被Yandex团队禁止。Yandex不会单独为您提供地图上的任何流量数据。我建议你看看谷歌地图Api,在那里你可以获得你指定路线的交通信息。示例:

    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/

相关内容

  • 没有找到相关文章

最新更新