by Gerard Sans | @gerardsans
SANS
GERARD
Spoken at 143 events in 37 countries
🦄
🌩️
No servers to manage
Fault tolerance High availability
Never pay for idle usage
Auto-scales immediately
$
interactions
storage
notifications
auth
analytics
function
amplify add <category>
api
hosting
xr
transcribe
rekognition
translate
comprehend
amplify add predictions
polly
/BikePoint
/BikePoint/id
/BikePoint/Search
[
{
"id": "BikePoints_1",
"commonName": "River Street , Clerkenwell",
"additionalProperties": [{
"key": "NbBikes", "value": "11",
}],
"lat": 51.529163,
"lon": -0.10997
}
// 777 more
]
{
"id": "BikePoints_1",
"commonName": "River Street , Clerkenwell",
"additionalProperties": [{
"key": "NbBikes", "value": "11",
}],
"lat": 51.529163,
"lon": -0.10997
}
GeoJSONfeature
BikesPoint
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-0.10997, 51.529163]
},
"properties": {
"id": "BikePoints_1",
"name": "River Street , Clerkenwell"
}
}
Coordinates = [-0.10997, 51.529163]
51.529163
-0.10997
GeoJSONfeature
BikesPoint
mapbox Source
mapbox Layer
type BikePoint @model {
id: ID!
name: String!
description: String
location: Location
bikes: Int
}
// request VTL template
{
"version": "2018-05-29",
"method": "GET",
"resourcePath": "/BikePoint/$context.source.id",
}
// response VTL template
#set($body = $util.parseJson($ctx.result.body))
#if($ctx.error)
$util.error($ctx.error.message, $ctx.error.type)
#end
#if($ctx.result.statusCode == 200)
$body.additionalProperties[6].value
#else
#return
#end
type BikePoint @model @searchable {
id: ID!
name: String!
description: String
location: Location
bikes: Int
}
type Location {
lat: Float
lon: Float
}
type Query {
nearbyBikeStations(location: LocationInput!, m: Int, limit: Int)
}
GeoJSONfeature
BikesPoint
GraphQL API
Elastic Search
# Create index
PUT /bikepoint
# Setup location type as geo_point
PUT /bikepoint/_mapping/doc
{
"properties": {
"location": {
"type": "geo_point"
}
}
}
mutation addBikePoint {
createBikePoint(input: {
id: "BikePoints_1"
name: "River Street , Clerkenwell"
location: {
lat: 51.529163
lon: -0.10997
}
}) { id }
}
GET /bikepoint/doc/_search
{
"query": {
"bool" : {
"must" : { "match_all" : {} },
"filter" : {
"geo_distance" : {
"distance" : "500m",
"distance_type": "arc",
"location" : {
"lon": -0.134167, "lat": 51.510239
}
"sort": [{
"_geo_distance": {
"location": {
"lon": -0.134167, "lat": 51.510239
},
"order": "asc",
"unit": "m",
"distance_type": "arc"
}
}]
}
[lon1, lat1]
[lon2, lat2]
Haversine Formula
Great-circle distance
double distance(double lat1, double lon1, double lat2, double lon2) {
return 6378137 * haversine(lat1, lon1, lat2, lon2);
}
double haversine(double lat1, double lon1, double lat2, double lon2) {
double hsinX = Math.sin((lon1 - lon2) * 0.5);
double hsinY = Math.sin((lat1 - lat2) * 0.5);
double h = hsinY * hsinY + (Math.cos(lat1) * Math.cos(lat2) * hsinX * hsinX);
return 2 * Math.atan2(Math.sqrt(h), Math.sqrt(1 - h));
}
@undef_obj
@kurtiskemple
@dabit3
@TheSwaminator