Travel Time Python SDK ช่วยให้ผู้ใช้ค้นหาสถานที่ตามเวลาการเดินทาง แทนที่จะใช้ระยะทาง "เหมือนแมลงวัน"
การค้นหาตามเวลาทำให้ผู้ใช้มีโอกาสมากขึ้นในการปรับเปลี่ยนในแบบของคุณและให้การค้นหาที่เกี่ยวข้องมากขึ้น
ติดตั้ง Travel Time Python SDK ใน virtualenv
โดยใช้ pip
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 คุณจะต้องระบุรหัสแอปพลิเคชันและคีย์ 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