traveltime python sdk
v3.9.17 - Adding Time Map
Travel Time Python SDK 帮助用户通过行程时间而不是使用“直线距离”来查找位置。
基于时间的搜索为用户提供了更多个性化机会并提供更相关的搜索。
使用pip
在virtualenv
中安装 Travel Time Python SDK。 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