Search code examples
pythongoogle-maps-api-3mapsgoogle-directions-api

How do I mention only the major highways as output rather than local roads?


I am using Directions API to get a route segment (list of destinations to reach a particular destination).

origin = "New York"
destination = "Ohio"
output: ['2 Murray Street, New York, NY 10007, USA', '50 14th St, Jersey City, NJ 07310, USA', '5710 Newark - Jersey City Tpke, Kearny, NJ 07032, USA', 'US 46, 07058, , New Jersey, United States', '192 Waring Dr, Delaware Water Gap, PA 18327, USA', '4891 E County Line Rd, Mineral Ridge, OH 44440, USA', ', 44451, , Ohio, United States', '914&, 916 Rosamond Ave, Akron, OH 44307, USA', '1090 W Wilbeth Rd, Akron, OH 44314, USA', 'US 224, 44273, , Ohio, United States', 'I 71, 43334, , Ohio, United States', '3970 OH-229, Marengo, OH 43334, USA', '2390 OH-229, Ashley, OH 43003, USA']

the desired output: The above list shows each and every address I need to go through to reach Ohio from New York. I wish to get only the HIGHWAY/EXPRESSWAY/MAJOR ROADS

I have an origin and a destination. I wish to get a list of Highways which I have to take in order to reach the destination from the origin (mode=driving).


Solution

  • There's no such feature in the Directions API

    While it is possible to avoid highways, it is not possible to prioritize highways as of writing this as per the documentation.

    Directions API can force the route for which it returns a distance not to take any highways, but the opposite is not true. In other words, there's no option to make the API only return routes through highways.

    What I could suggest as a workaround is that you use waypoints on Directions API to manually force the API to use a highway by making the route go through coordinates of your choice, though it'd be a more manual process. You can read more on waypoints here: https://developers.google.com/maps/documentation/directions/get-directions#waypoints

    Another thing I would like to suggest is for you to file Feature Request in the Public Issue Tracker and add your use case that might help Google Engineers consider such feature. Here's a link that would help you get started: https://developers.google.com/maps/support#issue_tracker

    Please note that a Google Public Issue Tracker entry is the authoritative source for public information regarding the feature request that you'll post, and all publicly-relevant updates will be posted there.

    Note: It would also be great if you can edit your question and link the Feature Request you filed/will file here.

    I hope this helps!