Reputation: 11
I've been trying to add an route line to a tkintermapview simple app, but i can't find a code that matches what i need i have a list with around 10 places that i need to calculate the distance in a specific route to get the trasportation fee.
I tried using this code line that i got with AI but it didn't work, and while searching about i just found information on other mapping tools for python like kivy and canvas.
Here's the code that the AI sugested to use in order to get the desired result:
def draw_route(self, coords):
for coord in coords:
self.map_widget.set_marker(coord[0], coord[1], text="Point", marker_color="red")
for i in range(len(coords) - 1):
self.map_widget.set_path(coords[i][0], coords[i][1], coords[i + 1][0], coords[i + 1][1], color="blue")
I have another function that calculates the distance but it is all buggy since i can't show the exact route that i have.
here is the code line that is used to calculate the distance between the two points:
def calculate_distance(self):
if len(self.route_coords) <2:
self.distance_label.configure(text="***")
return
total_distance = 0
for i in range(len(self.route_coords) - 1):
start = self.route_coords[i]
end = self.route_coords[i + 1]
total_distance += great_circle(start, end).kilometers
self.distance_label.configure(text=f"****: {total_distance: .2f} KM")
Upvotes: 1
Views: 94