Mastering Development

OSMnx: Is there a way to find an accurate shortest path between 2 coordinates?

I want to ask if there is a way to find the accurate shortest path between 2 coordinates.
The 2 coordinates are (-33.889606, 151.283306), (-33.889927, 151.280497) as shown in the picture.enter image description here
The black path is the ideal path, and the red one uses get_nearest_node.
Here are the codes:

import folium
import osmnx as ox
import networkx as nx

ox.config(use_cache=True, log_console=True)

G = ox.graph_from_point((-33.889606, 151.283306), dist=3000, network_type='drive')

G = ox.speed.add_edge_speeds(G)
G = ox.speed.add_edge_travel_times(G)

orig = ox.get_nearest_node(G, (-33.889606, 151.283306))
dest = ox.get_nearest_node(G, (-33.889927, 151.280497))
route = nx.shortest_path(G, orig, dest, 'travel_time')

route_map = ox.plot_route_folium(G, route)'test.html')

Leave a Reply

Your email address will not be published. Required fields are marked *