Le SDK Python Travel Time aide les utilisateurs à trouver des emplacements en fonction du temps de trajet plutôt que d'utiliser la distance « à vol d'oiseau ».
La recherche basée sur le temps offre aux utilisateurs plus de possibilités de personnalisation et permet une recherche plus pertinente.
Installez le SDK Python Travel Time dans un virtualenv
à l'aide de pip
. virtualenv
est un outil pour créer des environnements Python isolés.
virtualenv
permet d'installer le SDK Python Travel Time sans avoir besoin d'autorisations d'installation du système et sans entrer en conflit avec les dépendances du système installées.
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
Afin de vous authentifier auprès de l'API Travel Time, vous devrez fournir l'ID d'application et la clé API.
from traveltimepy import TravelTimeSdk
sdk = TravelTimeSdk ( app_id = "YOUR_APP_ID" , api_key = "YOUR_APP_KEY" )
Étant donné les coordonnées d'origine, trouvez les formes des zones accessibles dans le temps de trajet correspondant.
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 ())
Étant donné les coordonnées d’origine, trouvez les intersections des formes spécifiées.
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 ())
Étant donné les coordonnées d’origine, trouvez les unions de formes spécifiées.
Recherche l'union des formes spécifiées.
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 ())
Une version très rapide de time_map()
. Cependant, les paramètres de requête sont beaucoup plus limités.
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 ())
Étant donné les coordonnées d'origine, trouvez les formes des zones accessibles dans la distance de déplacement correspondante.
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 ())
Les points d'origine et de destination donnés filtrent les points qui ne peuvent pas être atteints dans le délai spécifié. Découvrez les temps de trajet, les distances et les coûts entre une origine et jusqu'à 2 000 points de destination.
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 ())
Une version très rapide de time_filter()
. Cependant, les paramètres de requête sont beaucoup plus limités.
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 ())
Une version rapide du filtre temporel communiquant à l'aide de tampons de protocole.
Les paramètres de requête sont beaucoup plus limités et seul le temps de trajet est renvoyé. De plus, les résultats ne sont qu'approximativement corrects (95 % des résultats sont garantis à moins de 5 % des itinéraires renvoyés par le filtre temporel régulier). Cette rigidité s'accompagne de l'avantage de temps de réponse plus rapides (plus de 5 fois plus rapides par rapport au filtre temporel normal) et de limites plus larges sur le nombre de points de destination.
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 ())
Renvoie les informations de routage entre la source et les destinations.
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