programing

웹 서비스를 통해 Google의 트래픽 데이터에 액세스

nasanasas 2020. 10. 30. 08:11
반응형

웹 서비스를 통해 Google의 트래픽 데이터에 액세스


Google이 웹 서비스를 통해 제공하는 교통 데이터에 액세스 할 수있는 방법이 있습니까?

GTrafficOverlay포함 된 Google지도의 경로 위에 트래픽을 배치 하는 것으로 보이지만 소스와 목적지를 제공하고 둘 사이의 트래픽을 찾는 데 사용할 수있는 직접 웹 서비스가 없습니까?

이 데이터를 얻을 수있는 다른 소스가 있습니까?


Google Maps Javascript API v3에서 원시 트래픽 데이터를 가져올 수있는 방법은 없습니다 (또는 적어도 합리적이고 쉽고 편리한 방법은 없습니다). 그렇게 할 수 있더라도 Google지도 서비스 약관의 일부 조항을 위반할 가능성이 있습니다. 다른 서비스에서이 정보를 얻어야합니다. 현재이 정보를 제공하는 무료 서비스가 있는지는 의심 스럽지만 누군가가 저를 틀렸다는 것을 증명하면 좋겠습니다.

@crdzoba가 지적했듯이 Bing Maps API는 일부 트래픽 데이터를 노출합니다 . 아마도 그것은 당신의 필요를 채울 수 있습니다. "사건"에 대한 데이터 일 뿐이므로 노출되는 트래픽 데이터의 양은 문서에서 명확하지 않습니다. 공사로 인한 느린 교통 체증이있을 것이지만, 단순히 볼륨으로 인한 느린 교통 체증이 있을지는 분명하지 않습니다.

업데이트 (2016 년 3 월) :이 답변이 2011 년에 작성된 이후로 많은 일이 발생했지만 핵심 사항은 그대로 유지되는 것 같습니다. 무료 API 서비스 에서 원시 트래픽 데이터찾을 수 없습니다 (적어도 미국에서는 그렇지 않을 것입니다. 대부분의 다른 장소). 그러나 약간의 비용을 지불해도 괜찮거나 "교통량을 고려한 특정 경로의 이동 시간"과 같은 것이 필요한 경우 옵션이 있습니다. 예를 들어 @Anto의 답변 은 트래픽을 고려하여 이동 시간을 얻을 수있는 유료 API 서비스로서 Google의 Maps For Work가리 킵니다 .


이 정보는 전문가 용 Maps for Work 에서 Google Directions API사용하여 사용할 수 있습니다 . API의 문서 에 따르면 :

참고 : Maps for Work 사용자는 키 대신 요청에 클라이언트 및 서명 매개 변수를 포함해야합니다.
[...]
duration_in_traffic 은 현재 교통 상황을 고려하여이 구간의 총 소요 시간을 나타냅니다. 트래픽 기간은 다음이 모두 참인 경우에만 반환됩니다.

  • 길 찾기 요청에는 현재 시간에서 몇 분 이내의 값으로 설정된 출발 시간 매개 변수가 포함됩니다.
  • 요청에는 유효한 Google Maps API for Work 클라이언트 및 서명 매개 변수가 포함 됩니다.
  • 요청한 경로에 대한 교통 상황을 확인할 수 있습니다.
  • 길 찾기 요청에는 경유지 경유지가 포함되지 않습니다.

Bing Maps API에는 교통 정보를 반환하는 REST 서비스가 있습니다.

http://msdn.microsoft.com/en-us/library/hh441725


HERE MAP SERVICE를 살펴 보시기 바랍니다. 그들은 당신이 사용할 수있는 직접적인 교통 데이터를 가지고 있으며, 정확히 당신이 필요로하는 것입니다 : https://developer.here.com/api-explorer/rest/traffic/traffic-flow-bounding-box

예를 들어 관심 영역을 쿼리하면 다음과 같은 결과를 얻을 수 있습니다.

{
  "RWS": [
    {
      "RW": [
        {
          "FIS": [
            {
              "FI": [
                {
                  "TMC": {
                    "PC": 32483,
                    "DE": "SOHO",
                    "QD": "+",
                    "LE": 0.71682
                  },
                  "CF": [
                    {
                      "TY": "TR",
                      "SP": 9.1,
                      "SU": 9.1,
                      "FF": 17,
                      "JF": 3.2911,
                      "CN": 0.9
                    }
                  ]
                }
              ]
            }
          ],
....

이 예는 현재 평균 속도 SU9.1을 보여 주며 , 여기서 자유 흐름 속도 FF는 17입니다. Jam factor JF는 3.3이며 여전히 자유 흐름으로 간주 되지만 느려 집니다. 사용 된 단위 (마일 / km)는 API 호출에서 정의 할 수 있습니다. TMC 위치를 처리하지 않으려면 요청을 추가하여 도로 구간의 지리 좌표를 요청할 수 있습니다 responseattributes=sh.

사용 된 약어는 여기에서 찾을 수 있습니다. Interpreting HERE Maps real-time traffic tags :

  • "RWS"-도로 (RW) 항목 목록
  • "RW"= 이것은 전체 도로를 가로 지르는 흐름에 대한 복합 항목입니다. 사용 가능한 교통 흐름 정보와 함께 각 도로에 대한 도로 항목이 표시됩니다.
  • "FIS"= 플로우 항목 (FI) 요소 목록
  • "FI"= 단일 흐름 항목
  • "TMC"= 주문 된 TMC 위치 모음
  • "PC"= 포인트 TMC 위치 코드
  • "DE"= 도로에 대한 텍스트 설명
  • "QD"= 대기열 방향. '+'또는 '-'. 이는 정규화 된 ID의 이동 방향과 반대입니다. 예를 들어 위치 107 + 03021의 경우 QD는 '-'입니다.
  • "LE"= 도로 연장 길이. 단위는 파일 헤더에 정의됩니다.
  • "CF"= 현재 흐름. 이 요소에는 지정된 흐름 항목의 속도 및 Jam Factor 정보에 대한 세부 정보가 포함됩니다.
  • "CN"= 신뢰도, 속도 결정 방법을 나타냅니다. -1.0 도로 폐쇄. 1.0 = 100 % 0.7-100 % 과거 일반적으로 .7과 1.0 사이의 값 "FF"=이
    도로 구간의 자유 유속 입니다.
  • "JF"= 예상되는 여행 품질을 나타내는 0.0에서 10.0 사이의 숫자입니다. 도로가 폐쇄되면 Jam Factor는 10이됩니다. 10.0에 가까워지면 여행의 질이 나빠집니다. -1.0은 Jam Factor를 계산할 수 없음을 나타냅니다.
  • "SP"= 속도 제한에 의해 제한되는 속도 (UNIT 기준)
  • "SU"= 속도 제한에 의해 제한되지 않는 속도 (UNIT 기준)
  • "TY"= 지정된 위치 참조 컨테이너에 대한 유형 정보. 자유롭게 정의 된 문자열 일 수 있습니다.

또한 소스는 https://developer.here.com/rest-apis/documentation/traffic/topics/additional-parameters.html 에서 제공됩니다.


인도에서는 http://www.itrafficnews.com을 사용하고 있습니다. 그러나 데이터는 사용자가 게시합니다. 나는 구글이 데이터를 제공 할 것이라고 생각하지 않는다.


원시 트래픽 데이터를 가져 오는 대신 다른 접근 방식을 시도 할 수 있습니다. Google Directions API를 사용하면 특정 경로로 API를 쿼리하고 결과로 JSON 문자열 또는 XML 요소를 반환 할 수 있습니다. 이 결과에는 'duration_in_traffic'요소가 포함됩니다. 이는 현재 교통 상황을 고려하여 특정 여정 구간의 총 소요 시간을 나타냅니다. ( 'leg'및 기타 Directions API에서 반환하는 JSON 문자열 요소에 대한 자세한 내용은 아래 링크를 참조하십시오.)

https://developers.google.com/maps/documentation/directions/#JSON 직접 시도하지는 않았지만 설명서에서 발견 한 것입니다.


Mapquests Traffic API ( http://www.mapquestapi.com/traffic/)를 살펴 보시기 바랍니다 .

The webservice is unfortunately only available for some citys in the US, I think. But probably it solves your problem.


I don't think Google will provide this API. And traffic data not only contains the incident data.

Today many online maps show city traffic, but they have not provide the API for the developer. We even don't know where they get the traffic data. Maybe the government has the data.

So I think you could think about it from another direction. For example, there are many social network website out there. Everybody could post the traffic information on the website. We can collection these information to get the traffic status. Or maybe we can create a this type website.

But that type traffic data (talked about above) is not accurate. Even the information provided by human will be wrong.

Luckily I found that my city now provides an Mobile App called "Real-time Bus Information". It could tell the citizen where the bus is now, and when will arrive at the bus station. And I sniff the REST API in this App. The data from REST API give the important data, for example the lat and lon, and also the bus speed. And it's real-time data! So I think we could compute the traffic status from these data (by some programming). Here is some sample data : https://github.com/sp-chenyang/bus/blob/master/sample_data/bjgj_aibang_com_8899_bjgj_php_city_linename_stationno_datatype_type.json

Even the bus data will not enough to compute the accurate real-time traffic status. Incidents, traffic light and other things will affect the traffic status. But I think this is the beginning.

At the end, I think you could try to find whether your city provides these data.

PS: I am always thinking that life will be better for people in the future , but not now.


It is possible to get traffic data. Below is my implementation in python. The API has some quota & is not fully free, but good enough for small projects

import requests
import time
import json


while True:

    url = "https://maps.googleapis.com/maps/api/distancematrix/json"

    querystring = {"units":"metric","departure_time":str(int(time.time())),"traffic_model":"best_guess","origins":"ITPL,Bangalore","destinations":"Tin Factory,Bangalore","key":"GetYourKeyHere"}

    headers = {
        'cache-control': "no-cache",
        'postman-token': "something"
        }

    response = requests.request("GET", url, headers=headers, params=querystring)
    d = json.loads(response.text)
    print("On", time.strftime("%I:%M:%S"),"time duration is",d['rows'][0]['elements'][0]['duration']['text'], " & traffic time is ",d['rows'][0]['elements'][0]['duration_in_traffic']['text'])
    time.sleep(1800)
    print(response.text)

Response is :-

{
    "destination_addresses": [
        "Tin Factory, Swamy Vivekananda Rd, Krishna Reddy Industrial Estate, Dooravani Nagar, Bengaluru, Karnataka 560016, India"
    ],
    "origin_addresses": [
        "Whitefield Main Rd, Pattandur Agrahara, Whitefield, Bengaluru, Karnataka 560066, India"
    ],
    "rows": [
        {
            "elements": [
                {
                    "distance": {
                        "text": "10.5 km",
                        "value": 10505
                    },
                    "duration": {
                        "text": "35 mins",
                        "value": 2120
                    },
                    "duration_in_traffic": {
                        "text": "45 mins",
                        "value": 2713
                    },
                    "status": "OK"
                }
            ]
        }
    ],
    "status": "OK"
}

You need to pass "departure_time":str(int(time.time())) is a required query string parameter for traffic information.

Your traffic information would be present in duration_in_traffic.

Refer this documentation for more info.

https://developers.google.com/maps/documentation/distance-matrix/intro#traffic-model

참고URL : https://stackoverflow.com/questions/4600656/access-googles-traffic-data-through-a-web-service

반응형

'programing' 카테고리의 다른 글

XmlNode 값과 InnerText  (0) 2020.10.30
Firebase 및 GraphQL?  (0) 2020.10.30
Git Bisect를 중단하는 방법  (0) 2020.10.30
서버 안드로이드에 이미지 업로드  (0) 2020.10.30
효율적인 목록 교차 알고리즘  (0) 2020.10.30