Osmand API

Kenichi5 years ago

Hello,

I'm testing API Osmand in Traccar, it works well thanks to your documentation.
But i want to try other params that are not mentionned in the documentation.
I meet difficulties.

For example, i've got a request like this :

http://localhost:5055/?id=123458&lat=50&lon=65×tamp=1559806980&hdop=5&altitude=35&speed=0

And i want to use the record_photo function, found here : https://github.com/osmandapp/osmand-api-demo

But how to use it? I'd love if you could give me a concrete example

http://localhost:5055/?id=123458&lat=50&lon=65×tamp=1559806980&hdop=5&altitude=35&speed=0&record_photo
Yuwan Kumara year ago
const base64 = require("base-64");

const id = YOUR_DEVICE_ID;
const lat = LATTITUTE;
const lon = LONGITUTE;
const timestamp = new Date().toISOString();
const hdop = HDOP;
const altitude = ALTITUTE;
const speed = SPEED;
const username = YOUR_EMAIL_OR_USERNAME;
const password = YOUR_PASSWORD;
const base64Auth = base64.encode(`${username}:${password}`);

const url = `http://YOUR_SERVER:5055/?id=${id}&lat=${lat}&lon=${lon}&timestamp=${timestamp}&hdop=${hdop}&altitude=${altitude}&speed=${speed}`;
// Send POST request
fetch(url, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    Authorization: `Basic ${base64Auth}`,
  },
  //   body: JSON.stringify(data),
})
  .then((response) => {
    if (response.ok) {
      console.log("Write request sent successfully!");
    } else {
      console.log(response);
      throw new Error("Failed to send write request.");
    }
  })
  .catch((error) => {
    console.error("Error:", error);
  });