0

I am using GoogleMaps Directions API to extract the main road one can take from origin to destination as an output.

Origin: Stuttgart, Germany Destination: Frankfurt, Germany Output: ['A6']

The function get_route_segment() extracts the list of main roads to take to reach destination from Origin.

Furthermore, for instance we get the output as 'A6' (Autobahn 6) to reach 'Frankfurt, Germany' from 'Stuttgart, Germany'. But 'A6' extends all across the country. I want to analyse 'A6' between origin and destination using Chat GPT. How can I input 'A6' between origin and destination rather than analysing the whole 'A6'

def get_route_segment(api_key, origin, destination):
    gmaps = googlemaps.Client(key=api_key)
    route_segment = []
    data = gmaps.directions(origin, destination)
    segment = data[0]["summary"]

    steps = data[0]['legs'][0]['steps']
    loco = ''
    for step in steps:
        travel_mode = step['travel_mode']

    if 'and' in segment:
        route_segment = re.findall(r'\b[A-Z]\d+\b', segment)
        # route_segment = [uc.Autobahn(item) for item in route_segment]
        
    else:
        # route_segment.append(uc.Autobahn(segment))
        route_segment.append(segment)
    return route_segment

0 Answers0