Skip to content

Instantly share code, notes, and snippets.

View test.html
<html>
<head>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v1.3.0/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet/v1.3.0/leaflet.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
</head>
<body>
<div id="map" style="height: 100%;"></div>
<script>
View test.json
Error: Parse error on line 3514:
...": [] } ]}Request When a Route
-----------------^
Expecting 'EOF', '}', ',', ']'
{
"results": [
{
"search_id": "arrival search example",
"locations": [
View response.json
{
"results": [
{
"search_id": "arrival search example",
"locations": [
{
"id": "Hyde Park",
"properties": [
{
"travel_time": 1499,
View Arrival search
View Departure search
View Add locations
"locations": [
{
"id": "London center",
"coords": {
"lat": 51.508930,
"lng": -0.131387
}
},
{
"id": "Hyde Park",
View Request
POST /v4/routes HTTP/1.1
Host: api.traveltimeapp.com
Content-Type: application/json
Accept: application/json
X-Application-Id: ...
X-Api-Key: ...
{
"locations": [
{
View JSON response to GEOJSON
{
"results": [
{
"search_id": "7f45bc64-b567-4453-9477-50d4ce928690",
"shapes": [
{
"shell": [
{
"lat": 51.51180324,
"lng": -0.17239974000000036
View JSON to GeoJSON in Python
import json
def remap_linear_ring(linear_ring):
return list(map(lambda c: [c['lng'], c['lat']], linear_ring))
def shapes_to_multipolygon(shapes):
allRings = []
for shape in shapes:
shell = remap_linear_ring(shape['shell'])
holes = list(map(lambda h:remap_linear_ring(h), shape['holes']))
View Complete code
The complete code for reference:
function remapLinearRing(linearRing) {
return linearRing.map(c => [c['lng'], c['lat']]);
}
function shapesToMultiPolygon(shapes) {
var allRings = shapes.map(function (shape) {
var shell = remapLinearRing(shape['shell']);
var holes = shape['holes'].map(h => remapLinearRing(h));
You can’t perform that action at this time.