移動時間 Python SDK を使用すると、ユーザーは「時間どおりの」距離を使用するのではなく、移動時間に基づいて場所を見つけることができます。
時間ベースの検索により、ユーザーにパーソナライズの機会が増え、より関連性の高い検索が提供されます。
pip
を使用して、Travel Time Python SDK をvirtualenv
にインストールします。 virtualenv
分離された Python 環境を作成するツールです。
virtualenv
使用すると、システムのインストール権限を必要とせず、インストールされているシステムの依存関係と衝突することなく、Travel Time Python SDK をインストールできます。
pip3 install virtualenv
virtualenv <your-env>
source <your-env>/bin/activate
<your-env>/bin/pip install traveltimepy
pip install virtualenv
virtualenv <your-env>
<your-env>Scriptsactivate
<your-env>Scriptspip.exe install traveltimepy
Travel Time API で認証するには、アプリケーション ID と API キーを指定する必要があります。
from traveltimepy import TravelTimeSdk
sdk = TravelTimeSdk ( app_id = "YOUR_APP_ID" , api_key = "YOUR_APP_KEY" )
原点座標が与えられた場合、対応する移動時間内に到達可能なゾーンの形状を見つけます。
import asyncio
from datetime import datetime
from traveltimepy import Driving , Coordinates , TravelTimeSdk
async def main ():
sdk = TravelTimeSdk ( "YOUR_APP_ID" , "YOUR_APP_KEY" )
results = await sdk . time_map_async (
coordinates = [ Coordinates ( lat = 51.507609 , lng = - 0.128315 ), Coordinates ( lat = 51.517609 , lng = - 0.138315 )],
arrival_time = datetime . now (),
transportation = Driving ()
)
print ( results )
asyncio . run ( main ())
import asyncio
from datetime import datetime
from traveltimepy import Driving , Coordinates , TravelTimeSdk
async def main ():
sdk = TravelTimeSdk ( "YOUR_APP_ID" , "YOUR_APP_KEY" )
results = await sdk . time_map_geojson_async (
coordinates = [ Coordinates ( lat = 51.507609 , lng = - 0.128315 ), Coordinates ( lat = 51.517609 , lng = - 0.138315 )],
arrival_time = datetime . now (),
transportation = Driving ()
)
print ( results )
asyncio . run ( main ())
import asyncio
from datetime import datetime
from traveltimepy import Driving , Coordinates , TravelTimeSdk
async def main ():
sdk = TravelTimeSdk ( "YOUR_APP_ID" , "YOUR_APP_KEY" )
response = await sdk . time_map_wkt_async (
coordinates = [ Coordinates ( lat = 51.507609 , lng = - 0.128315 ), Coordinates ( lat = 51.517609 , lng = - 0.138315 )],
arrival_time = datetime . now (),
transportation = Driving ()
)
response . pretty_print () # for a custom formatted response
print ( response ) # default Python print
asyncio . run ( main ())
import asyncio
from datetime import datetime
from traveltimepy import Driving , Coordinates , TravelTimeSdk
async def main ():
sdk = TravelTimeSdk ( "YOUR_APP_ID" , "YOUR_APP_KEY" )
response = await sdk . time_map_wkt_no_holes_async (
coordinates = [ Coordinates ( lat = 51.507609 , lng = - 0.128315 ), Coordinates ( lat = 51.517609 , lng = - 0.138315 )],
arrival_time = datetime . now (),
transportation = Driving ()
)
response . pretty_print () # for a custom formatted response
print ( response ) # default Python print
asyncio . run ( main ())
与えられた原点座標で、指定された形状の交点を見つけます。
import asyncio
from datetime import datetime
from traveltimepy import Driving , Coordinates , TravelTimeSdk
async def main ():
sdk = TravelTimeSdk ( "YOUR_APP_ID" , "YOUR_APP_KEY" )
results = await sdk . intersection_async (
coordinates = [ Coordinates ( lat = 51.507609 , lng = - 0.128315 ), Coordinates ( lat = 51.517609 , lng = - 0.138315 )],
arrival_time = datetime . now (),
transportation = Driving ()
)
print ( results )
asyncio . run ( main ())
原点座標を指定して、指定された形状の和集合を見つけます。
指定された形状の結合を見つけます。
import asyncio
from datetime import datetime
from traveltimepy import Driving , Coordinates , TravelTimeSdk
async def main ():
sdk = TravelTimeSdk ( "YOUR_APP_ID" , "YOUR_APP_KEY" )
results = await sdk . union_async (
coordinates = [ Coordinates ( lat = 51.507609 , lng = - 0.128315 ), Coordinates ( lat = 51.517609 , lng = - 0.138315 )],
arrival_time = datetime . now (),
transportation = Driving ()
)
print ( results )
asyncio . run ( main ())
time_map()
の非常に高速なバージョン。ただし、リクエストパラメータはさらに制限されています。
import asyncio
from traveltimepy import Coordinates , TravelTimeSdk
from traveltimepy . dto . requests . time_map_fast import Transportation
async def main ():
sdk = TravelTimeSdk ( "YOUR_APP_ID" , "YOUR_APP_KEY" )
results = await sdk . time_map_fast_async (
coordinates = [ Coordinates ( lat = 51.507609 , lng = - 0.128315 ), Coordinates ( lat = 51.517609 , lng = - 0.138315 )],
transportation = Transportation ( type = "driving+ferry" ),
travel_time = 900
)
print ( results )
asyncio . run ( main ())
import asyncio
from traveltimepy import Coordinates , TravelTimeSdk
from traveltimepy . dto . requests . time_map_fast import Transportation
async def main ():
sdk = TravelTimeSdk ( "YOUR_APP_ID" , "YOUR_APP_KEY" )
results = await sdk . time_map_fast_geojson_async (
coordinates = [ Coordinates ( lat = 51.507609 , lng = - 0.128315 ), Coordinates ( lat = 51.517609 , lng = - 0.138315 )],
transportation = Transportation ( type = "driving+ferry" ),
travel_time = 900
)
print ( results )
asyncio . run ( main ())
import asyncio
from traveltimepy import Coordinates , TravelTimeSdk
from traveltimepy . dto . requests . time_map_fast import Transportation
async def main ():
sdk = TravelTimeSdk ( "YOUR_APP_ID" , "YOUR_APP_KEY" )
results = await sdk . time_map_fast_wkt_async (
coordinates = [ Coordinates ( lat = 51.507609 , lng = - 0.128315 ), Coordinates ( lat = 51.517609 , lng = - 0.138315 )],
transportation = Transportation ( type = "driving+ferry" ),
travel_time = 900
)
print ( results )
asyncio . run ( main ())
import asyncio
from traveltimepy import Coordinates , TravelTimeSdk
from traveltimepy . dto . requests . time_map_fast import Transportation
async def main ():
sdk = TravelTimeSdk ( "YOUR_APP_ID" , "YOUR_APP_KEY" )
results = await sdk . time_map_fast_wkt_no_holes_async (
coordinates = [ Coordinates ( lat = 51.507609 , lng = - 0.128315 ), Coordinates ( lat = 51.517609 , lng = - 0.138315 )],
transportation = Transportation ( type = "driving+ferry" ),
travel_time = 900
)
print ( results )
asyncio . run ( main ())
原点座標が与えられた場合、対応する移動距離内で到達可能なゾーンの形状を見つけます。
import asyncio
from datetime import datetime
from traveltimepy import Driving , Coordinates , TravelTimeSdk
async def main ():
sdk = TravelTimeSdk ( "YOUR_APP_ID" , "YOUR_APP_KEY" )
results = await sdk . distance_map_async (
coordinates = [ Coordinates ( lat = 51.507609 , lng = - 0.128315 ), Coordinates ( lat = 51.517609 , lng = - 0.138315 )],
arrival_time = datetime . now (),
transportation = Driving ()
)
print ( results )
asyncio . run ( main ())
指定された出発点と目的地は、指定された制限時間内に到達できない点を除外します。出発地と最大 2,000 か所の目的地間の移動時間、距離、料金を調べます。
import asyncio
from datetime import datetime
from traveltimepy import Location , Coordinates , PublicTransport , Property , FullRange , TravelTimeSdk
async def main ():
sdk = TravelTimeSdk ( "YOUR_APP_ID" , "YOUR_APP_KEY" )
locations = [
Location ( id = "London center" , coords = Coordinates ( lat = 51.508930 , lng = - 0.131387 )),
Location ( id = "Hyde Park" , coords = Coordinates ( lat = 51.508824 , lng = - 0.167093 )),
Location ( id = "ZSL London Zoo" , coords = Coordinates ( lat = 51.536067 , lng = - 0.153596 ))
]
results = await sdk . time_filter_async (
locations = locations ,
search_ids = {
"London center" : [ "Hyde Park" , "ZSL London Zoo" ],
"ZSL London Zoo" : [ "Hyde Park" , "London center" ],
},
departure_time = datetime . now (),
travel_time = 3600 ,
transportation = PublicTransport ( type = "bus" ),
properties = [ Property . TRAVEL_TIME ],
range = FullRange ( enabled = True , max_results = 3 , width = 600 )
)
print ( results )
asyncio . run ( main ())
time_filter()
の非常に高速なバージョン。ただし、リクエストパラメータはさらに制限されています。
import asyncio
from traveltimepy import Location , Coordinates , Transportation , TravelTimeSdk
async def main ():
sdk = TravelTimeSdk ( "YOUR_APP_ID" , "YOUR_APP_KEY" )
locations = [
Location ( id = "London center" , coords = Coordinates ( lat = 51.508930 , lng = - 0.131387 )),
Location ( id = "Hyde Park" , coords = Coordinates ( lat = 51.508824 , lng = - 0.167093 )),
Location ( id = "ZSL London Zoo" , coords = Coordinates ( lat = 51.536067 , lng = - 0.153596 ))
]
results = await sdk . time_filter_fast_async (
locations = locations ,
search_ids = {
"London center" : [ "Hyde Park" , "ZSL London Zoo" ],
"ZSL London Zoo" : [ "Hyde Park" , "London center" ],
},
transportation = Transportation ( type = "public_transport" ),
one_to_many = False
)
print ( results )
asyncio . run ( main ())
プロトコル バッファを使用して通信するタイム フィルターの高速バージョン。
リクエスト パラメータはさらに限定されており、移動時間のみが返されます。さらに、結果はほぼ正しいものにすぎません (結果の 95% が、通常の時間フィルターによって返されるルートの 5% 以内にあることが保証されます)。この柔軟性のなさには、応答時間が短縮され (通常の時間フィルターと比較して 5 倍以上高速)、宛先ポイントの量に対する制限が大きくなるという利点があります。
import asyncio
from traveltimepy import ProtoCountry , Coordinates , ProtoTransportation , TravelTimeSdk , PropertyProto
async def main ():
sdk = TravelTimeSdk ( "YOUR_APP_ID" , "YOUR_APP_KEY" )
travel_times = await sdk . time_filter_proto_async (
origin = Coordinates ( lat = 51.425709 , lng = - 0.122061 ),
destinations = [
Coordinates ( lat = 51.348605 , lng = - 0.314783 ),
Coordinates ( lat = 51.337205 , lng = - 0.315793 )
],
transportation = ProtoTransportation . DRIVING_FERRY ,
travel_time = 7200 ,
country = ProtoCountry . UNITED_KINGDOM ,
properties = [ PropertyProto . DISTANCE ],
)
print ( travel_times )
asyncio . run ( main ())
送信元と宛先間のルーティング情報を返します。
import asyncio
from datetime import datetime
from traveltimepy import Location , Coordinates , PublicTransport , TravelTimeSdk
async def main ():
sdk = TravelTimeSdk ( "YOUR_APP_ID" , "YOUR_APP_KEY" )
locations = [
Location ( id = "London center" , coords