2011-07-29 4 views
2

ジオキットをレールで使用して2か所の間の見積り時間を取得する方法はありますか?今は遠く離れていることを示しているだけですが、より良いアプローチは15分離れていることを示しています - それはもっと実用的な遠方へのアプローチです(時には2マイルは10分、時には3度です)rails geokit - 旅行/通勤時間を取得

+0

2点間の道路やその他の移動手段を考慮する必要があります。あなたが短い旅行のための野球場にあなたを得る40のMPHのような大まかな値を使用したいだけなら。距離が増加するにつれて、より高速な制限を有する高速道路または高速道路を使用してユーザが移動する可能性が高くなる。 –

+0

良い点、デヴィン。私は交通量も考慮に入れましたので、40が良い見積もりです。私は本当の旅行時間は必要ないと思う。 – stewart715

+0

下記の私の答えを確認してください、良い方法があります! :) –

答えて

5

より良い解決策は、APIを使用してGoogle Maps Directions APIを使用することです。次のURLを呼び出すのと同じくらい簡単ですhttp://maps.googleapis.com/maps/api/directions/json?origin=Chicago,IL&destination=Los+Angeles,CA&waypoints=Joplin,MO|Oklahoma+City,OK&sensor=false。このJSONを返す :

{ 
    "status": "OK", 
    "routes": [ { 
    "summary": "I-40 W", 
    "legs": [ { 
     "steps": [ { 
     "travel_mode": "DRIVING", 
     "start_location": { 
      "lat": 41.8507300, 
      "lng": -87.6512600 
     }, 
     "end_location": { 
      "lat": 41.8525800, 
      "lng": -87.6514100 
     }, 
     "polyline": { 
      "points": "[email protected]", 
      "levels": "B?B" 
     }, 
     "duration": { 
      "value": 19, 
      "text": "1 min" 
     }, 
     "html_instructions": "Head \u003cb\u003enorth\u003c/b\u003e on \u003cb\u003eS Morgan St\u003c/b\u003e toward \u003cb\u003eW Cermak Rd\u003c/b\u003e", 
     "distance": { 
      "value": 207, 
      "text": "0.1 mi" 
     } 
     }, 
     ... 
     ... additional steps of this leg 
    ... 
    ... additional legs of this route 
     "duration": { 
     "value": 74384, 
     "text": "20 hours 40 mins" 
     }, 
     "distance": { 
     "value": 2137146, 
     "text": "1,328 mi" 
     }, 
     "start_location": { 
     "lat": 35.4675602, 
     "lng": -97.5164276 
     }, 
     "end_location": { 
     "lat": 34.0522342, 
     "lng": -118.2436849 
     }, 
     "start_address": "Oklahoma City, OK, USA", 
     "end_address": "Los Angeles, CA, USA" 
    } ], 
    "copyrights": "Map data ©2010 Google, Sanborn", 
    "overview_polyline": { 
     "points": "[email protected][email protected]`vnApw{A`[email protected]~w\\|[email protected]{[email protected]@b}@[email protected][email protected]@jc|Bx}C`[email protected]|@[email protected]}Axf][email protected][email protected]{A~d{A|[email protected]`cFp~xBc`[email protected]@[email protected][email protected]@[email protected]|{CbtY~jGqeMb{iF|n\\~mbDzeVh_Wr|Efc\\x`Ij{kE}mAb~uF{cNd}xBjp][email protected]|[email protected]_Kv~eGyqTj_|@`uV`k|[email protected]}[email protected][email protected]`CnvHx`[email protected]@j|[email protected]|[email protected]`[email protected][email protected]}[email protected]`@|}[email protected]@jakEitAn{fB_a]lexClshBtmqAdmY_hLxiZd~XtaBndgC", 
     "levels": "BBBAAAAABAABAAAAAABBAAABBAAAABBAAABABAAABABBAABAABAAAABABABABBABAABB" 
    }, 
    "warnings": [ ], 
    "waypoint_order": [ 0, 1 ], 
    "bounds": { 
     "southwest": { 
     "lat": 34.0523600, 
     "lng": -118.2435600 
     }, 
     "northeast": { 
     "lat": 41.8781100, 
     "lng": -87.6297900 
     } 
    } 
    } ] 
} 

その後、JSONをパースはduration.textをつかむと、あなたのページに表示するために戻りました。 このAPIを使用するには、利用規約に従わなければならない場合がありますので、Googleの要件を読み、サービスの使用にどのように影響するかを必ず確認してください。

関連する問題