Modest_coder
Modest_coder

Reputation: 11

Using the Wolfram API in python to obtain directions between multiple (lat, lng) points

I am trying to get the directions between multiple (lat, lng) points in python using the Wolfram API. I know this works on the wolfram notebook but I was wondering how I could adapt it to work with python. Right now im getting errors no matter what I try to access the API.

My code (in wolfram notebook):

td = TravelDirections[{GeoPosition[{40.7128, -74.0060}], GeoPosition[{25.7617, -80.1918}], GeoPosition[{19.4326, -99.1332}]}, TravelMethod ->"Biking"]

GeoGraphics[Style[Line[td], Thick, Red]]

td["Dataset"][All, {"Description", "Distance"}]

This works and returns a map image connecting the points and a list of directions

My code (in python):

import wolframalpha

import requests

wolfram_key="MY KEY"

client = wolframalpha.Client(wolfram_key)

td = client.query('TravelDirections[{GeoPosition[{40.7128, -74.0060}], GeoPosition[{19.4326, -99.1332}]}, TravelMethod ->"Walking"]')


map = client.query('GeoGraphics[Style[Line[td], Thick, Red]]')

direct = client.query('td["Dataset"][All, {"Description", "Distance"}]')

print(direct)

gets this error:

{'@success': False, '@error': 'false', '@xml:space': 'preserve', '@numpods': '0'                                                                                                                                                             , '@datatypes': '', '@timedout': '', '@timedoutpods': '', '@timing': '3.37700000                                                                                                                                                             00000002', '@parsetiming': '1.319', '@parsetimedout': 'false', '@recalculate': '                                                                                                                                                             ', '@id': '', '@parseidserver': '18', '@host': 'https://www6b3.wolframalpha.com'                                                                                                                                                             , '@server': '18', '@related': '', '@version': '2.6', '@inputstring': 'td["Datas                                                                                                                                                             et"][All, {"Description", "Distance"}]', 'didyoumeans': {'@count': '1', 'didyoum                                                                                                                                                             ean': {'@score': '0.379067', '@level': 'medium', '#text': 'All Description Dista                                                                                                                                                             nce'}}}

Upvotes: 1

Views: 64

Answers (0)

Related Questions