{"id":1375,"date":"2023-04-14T07:06:01","date_gmt":"2023-04-14T07:06:01","guid":{"rendered":"https:\/\/www.cartograph.eu\/v3\/?p=1375"},"modified":"2025-12-10T09:02:39","modified_gmt":"2025-12-10T09:02:39","slug":"custom-web-server-for-track-upload-and-track-search","status":"publish","type":"post","link":"https:\/\/www.cartograph.eu\/v3\/custom-web-server-for-track-upload-and-track-search\/","title":{"rendered":"Custom web server for track upload and track search"},"content":{"rendered":"\n<p>Cartograph Maps can upload tracks-, and send track search queries to your web server. You can add a custom webserver in the <a href=\"https:\/\/www.cartograph.eu\/v3\/user-account-manager\/\" data-type=\"post\" data-id=\"1372\">User account manager<\/a>.<\/p>\n\n\n\n<p>The following options are available:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Authentication<\/strong>: Allows to specify a username and password for authenticating with the web server.<\/li>\n\n\n\n<li><strong>Track search<\/strong>.<\/li>\n\n\n\n<li><strong>Track upload<\/strong>.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Track search<\/h2>\n\n\n\n<p>Track search allows you to search for tracks within the currently visible region. Track search can be accessed from the <a href=\"https:\/\/www.cartograph.eu\/v3\/search-manager\/\" data-type=\"post\" data-id=\"1129\"><strong>Search manager<\/strong><\/a>.<\/p>\n\n\n\n<p>The track search URL has the following format:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:&#47;&#47;www.cartograph.eu\/v3\/downloads\/tmp\/Stuhlecktour_Garmin.gpx?search={query}&amp;boundingbox={bbox}<\/code><\/pre>\n\n\n\n<p>The following query parameters are automatically replaced:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>{query}<\/strong>: A URL encoded (optional) search term which can be entered during track search.<\/li>\n\n\n\n<li><strong>{bbox}<\/strong>: The bounding box of the currently visible map region. The bounding box is a comma-separated string of the format &#8220;min longitude, max latitude, max longitude, min latitude&#8221; ( in other words: top left and bottom right coordinates).<\/li>\n<\/ul>\n\n\n\n<p>The web server has to return a plain <strong>GPX <\/strong>file which can include tracks, segments, and waypoints.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Track upload<\/h2>\n\n\n\n<p>The track upload tool uses HTTP multi-part POST for uploading a <strong>GPX <\/strong>formatted file to the web server saved in the HTTP form field &#8220;<strong>file<\/strong>&#8220;.<\/p>\n\n\n\n<p>After upload the server must return a JSON formatted reply:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n\t\"result\": true,\n\t\"message\": \"Upload success\"\n}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>&#8220;<strong>result<\/strong>&#8220;: true on success, false on failure.<\/li>\n\n\n\n<li>&#8220;<strong>message<\/strong>&#8220;: A message which is shown after upload.<\/li>\n<\/ul>\n\n\n\n<p><strong>Example<\/strong>: The following PHP script (generated with ChatGPT) shows how the uploaded track data can be handled on the server:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\/\/ Allow only POST requests\nif ($_SERVER&#91;'REQUEST_METHOD'] !== 'POST') {\n    http_response_code(405);\n    echo json_encode(&#91;\n        \"result\" =&gt; false,\n        \"message\" =&gt; \"Invalid request method\"\n    ]);\n    exit;\n}\n\n\/\/ Check if the file field exists\nif (!isset($_FILES&#91;'file']) || $_FILES&#91;'file']&#91;'error'] !== UPLOAD_ERR_OK) {\n    echo json_encode(&#91;\n        \"result\" =&gt; false,\n        \"message\" =&gt; \"No file uploaded or upload error\"\n    ]);\n    exit;\n}\n\n\/\/ OPTIONAL: Choose a destination folder\n$uploadDir = __DIR__ . '\/uploads';  \nif (!is_dir($uploadDir)) {\n    mkdir($uploadDir, 0777, true);\n}\n\n\/\/ Save the uploaded file\n$destination = $uploadDir . '\/' . basename($_FILES&#91;'file']&#91;'name']);\n\nif (move_uploaded_file($_FILES&#91;'file']&#91;'tmp_name'], $destination)) {\n    echo json_encode(&#91;\n        \"result\" =&gt; true,\n        \"message\" =&gt; \"Upload success\"\n    ]);\n} else {\n    echo json_encode(&#91;\n        \"result\" =&gt; false,\n        \"message\" =&gt; \"Could not move uploaded file\"\n    ]);\n}\n\n?&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Cartograph Maps can upload tracks-, and send track search queries to your web server. You can add a custom webserver<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1375","post","type-post","status-publish","format-standard","hentry","category-help"],"_links":{"self":[{"href":"https:\/\/www.cartograph.eu\/v3\/wp-json\/wp\/v2\/posts\/1375","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cartograph.eu\/v3\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cartograph.eu\/v3\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cartograph.eu\/v3\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cartograph.eu\/v3\/wp-json\/wp\/v2\/comments?post=1375"}],"version-history":[{"count":12,"href":"https:\/\/www.cartograph.eu\/v3\/wp-json\/wp\/v2\/posts\/1375\/revisions"}],"predecessor-version":[{"id":1740,"href":"https:\/\/www.cartograph.eu\/v3\/wp-json\/wp\/v2\/posts\/1375\/revisions\/1740"}],"wp:attachment":[{"href":"https:\/\/www.cartograph.eu\/v3\/wp-json\/wp\/v2\/media?parent=1375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cartograph.eu\/v3\/wp-json\/wp\/v2\/categories?post=1375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cartograph.eu\/v3\/wp-json\/wp\/v2\/tags?post=1375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}