How to pass coordinates to Map Matching API on python

Hi,

First of all thanks for a great tool!

This is probably just me don’t understanding the requests package, but how do I pass the coordinates to the map matching API on Python? I am following the documentation here, but I don’t quite get how to pass the gpx/coordinates?

Thanks in advance, Álvaro

The Python example in the docs seems to be missing the gpx file. Here is a working example:

api_key = "YOUR_API_KEY"
url = f"https://graphhopper.com/api/1/match?profile=car&key={api_key}"
gpx_file_path = "/path/to/some.gpx"
with open(gpx_file_path, "rb") as gpx_file:
    gpx_content = gpx_file.read()
headers = {"Content-Type": "application/gpx+xml"}
response = requests.post(url, headers=headers, data=gpx_content)

if response.status_code == 200:
    print("Request successful!")
else:
    print(f"Request failed with status code: {response.status_code}")
print(response.text)
2 Likes

Amazing, thank you very much!