Das Travel Time Python SDK hilft Benutzern, Standorte anhand der Reisezeit zu finden, anstatt die Entfernung „Luftlinie“ zu verwenden.
Die zeitbasierte Suche bietet Benutzern mehr Möglichkeiten zur Personalisierung und liefert eine relevantere Suche.
Installieren Sie das Travel Time Python SDK in einer virtualenv
mit pip
. virtualenv
ist ein Tool zum Erstellen isolierter Python-Umgebungen.
virtualenv
ermöglicht die Installation des Travel Time Python SDK, ohne dass Systeminstallationsberechtigungen erforderlich sind und ohne dass es zu Konflikten mit den installierten Systemabhängigkeiten kommt.
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
Um sich bei der Travel Time API zu authentifizieren, müssen Sie die Anwendungs-ID und den API-Schlüssel angeben.
from traveltimepy import TravelTimeSdk
sdk = TravelTimeSdk ( app_id = "YOUR_APP_ID" , api_key = "YOUR_APP_KEY" )
Finden Sie anhand der Ursprungskoordinaten Formen von Zonen, die innerhalb der entsprechenden Reisezeit erreichbar sind.
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 ())
Finden Sie bei gegebenen Ursprungskoordinaten Schnittpunkte bestimmter Formen.
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 ())
Finden Sie bei gegebenen Ursprungskoordinaten Vereinigungen bestimmter Formen.
Findet die Vereinigung angegebener Formen.
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 ())
Eine sehr schnelle Version von time_map()
. Die Anforderungsparameter sind jedoch viel eingeschränkter.
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 ())
Finden Sie anhand der Ursprungskoordinaten Formen von Zonen, die innerhalb der entsprechenden Reiseentfernung erreichbar sind.
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 ())
Angegebene Start- und Zielpunkte filtern Punkte heraus, die nicht innerhalb des angegebenen Zeitlimits erreicht werden können. Informieren Sie sich über Reisezeiten, Entfernungen und Kosten zwischen einem Startpunkt und bis zu 2.000 Zielpunkten.
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 ())
Eine sehr schnelle Version von time_filter()
. Die Anforderungsparameter sind jedoch viel eingeschränkter.
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 ())
Eine schnelle Version des Zeitfilters, der über Protokollpuffer kommuniziert.
Die Anfrageparameter sind viel eingeschränkter und es wird nur die Reisezeit zurückgegeben. Darüber hinaus sind die Ergebnisse nur annähernd korrekt (95 % der Ergebnisse liegen garantiert innerhalb von 5 % der vom regulären Zeitfilter zurückgegebenen Routen). Diese Inflexibilität bringt den Vorteil schnellerer Reaktionszeiten (mehr als fünfmal schneller im Vergleich zum regulären Zeitfilter) und größeren Beschränkungen für die Anzahl der Zielpunkte mit sich.
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 ())
Gibt Routing-Informationen zwischen Quelle und Zielen zurück.
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