This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Error: Parse error on line 3514: | |
...": [] } ]}Request When a Route | |
-----------------^ | |
Expecting 'EOF', '}', ',', ']' | |
{ | |
"results": [ | |
{ | |
"search_id": "arrival search example", | |
"locations": [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"results": [ | |
{ | |
"search_id": "arrival search example", | |
"locations": [ | |
{ | |
"id": "Hyde Park", | |
"properties": [ | |
{ | |
"travel_time": 1499, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"arrival_searches": [ | |
{ | |
"id": "arrival search example", | |
"departure_location_ids": [ | |
"Hyde Park", | |
"ZSL London Zoo" | |
], | |
"arrival_location_id": "London center", | |
"transportation": { | |
"type": "public_transport" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"departure_searches": [ | |
{ | |
"id": "departure search example", | |
"departure_location_id": "London center", | |
"arrival_location_ids": [ | |
"Hyde Park", | |
"ZSL London Zoo" | |
], | |
"transportation": { | |
"type": "driving" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"locations": [ | |
{ | |
"id": "London center", | |
"coords": { | |
"lat": 51.508930, | |
"lng": -0.131387 | |
} | |
}, | |
{ | |
"id": "Hyde Park", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
POST /v4/routes HTTP/1.1 | |
Host: api.traveltimeapp.com | |
Content-Type: application/json | |
Accept: application/json | |
X-Application-Id: ... | |
X-Api-Key: ... | |
{ | |
"locations": [ | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"results": [ | |
{ | |
"search_id": "7f45bc64-b567-4453-9477-50d4ce928690", | |
"shapes": [ | |
{ | |
"shell": [ | |
{ | |
"lat": 51.51180324, | |
"lng": -0.17239974000000036 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
NewerOlder