Skip to content

Commit

Permalink
Added maps for restaurants
Browse files Browse the repository at this point in the history
  • Loading branch information
afoeder committed Jun 10, 2024
1 parent 82ae89d commit 24f6587
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 3 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,13 @@ Through the years I have collected some recipes either passed down from relative
In an attempt to store them as well as possible, this is it.

Start with the [index](index.md).

## Publishin

### Writerside

At some point I've decided to give "Writerside" a try. All information is located in the folder `./Writerside`. The building happens by the `.github/workflows/build-docs.yml` file; it's basically what is described on the Docs for GH pages: https://www.jetbrains.com/help/writerside/deploy-docs-to-github-pages.html

The CNAME in the content root is for GitHub Pages.

### AMEX
2 changes: 1 addition & 1 deletion Writerside/topics/knowledge/AMEX-Dining-Credit-benefit.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ An AMEX Platinum card provides “Global Dining Credit” benefits.
* [Restaurants overview](https://www.americanexpress.com/de-de/benefits/diningbenefit/) (DE language)

<!--
<api-doc openapi-path="./amex-dining-credit-spec.yaml" endpoint="/country/{countryCode}/merchants" method="GET"/>
<api-doc openapi-path="../../../amex-dining-credit/amex-dining-credit-spec.yaml" endpoint="/country/{countryCode}/merchants" method="GET"/>
-->
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ paths:
required: true
schema:
type: string
pattern: '^\w{2}$'
pattern: '^\[A-Z]{2}$'
responses:
'200':
description: The list of merchants.
Expand Down Expand Up @@ -315,7 +315,7 @@ paths:
required: true
schema:
type: string
pattern: '^\w{2}$'
pattern: '^\[A-Z]{2}$'
responses:
'200':
description: The list of cities.
Expand Down
Binary file added amex-dining-credit/amex-dining-credit.paw
Binary file not shown.
96 changes: 96 additions & 0 deletions amex-dining-credit/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>AMEX Dining credit locations</title>
</head>
<body>

<div id="map" style="width: 80%;height: 80vh; margin: 0 auto"></div>
<script>
(g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
key: "AIzaSyCsQbB1qCK4L0OkFjsSu2gsySgP9hm6sIM",
v: "weekly",
// Use the 'v' parameter to indicate the version to use (weekly, beta, alpha, etc.).
// Add other bootstrap parameters as needed, using camel case.
});
</script>
<script>
!function() {
let map;

async function initMap() {
const { Map } = await google.maps.importLibrary("maps");

map = new Map(document.getElementById("map"), {
center: { lat: 51.163375, lng: 10.447683 },
zoom: 6,
mapId: "DEMO_MAP_ID"
});
}

initMap();

async function fillMarkers(country = "DE") {
const {Place} = await google.maps.importLibrary("places");
const { AdvancedMarkerElement } = await google.maps.importLibrary("marker");

let merchantsJson;
let cachedMerchantsData = localStorage.getItem("amex-dining-merchants-"+country);
if (!cachedMerchantsData) {
console.debug("No merchants info found in LocalStorage for "+country+", fetching from remote");
const amexApiMerchants =
await (
await fetch(
`https://dining-offers-prod.amex.r53.tuimedia.com/api/country/${country}/merchants`))
.json();
merchantsJson = await Promise.all(
amexApiMerchants.map(async (item) => {
const request = {
//@see https://developers.google.com/maps/documentation/javascript/place-search#example
textQuery: `${item.name}, ${item.address}, ${item.postcode} ${item.city.title}`,
fields: ["displayName", "location", "businessStatus"],
includedType: "restaurant",
maxResultCount: 1,
region: country,
useStrictTypeFiltering: false,
};
const { places } = await Place.searchByText(request);
let place = null;
if (places.length === 1) {
place = { location: places[0].location, name: places[0].displayName }
} else {
console.warn(`Places result for ${request.textQuery} is !== 1, places found:`, places)
}

return {
"name": item.name,
"place": place,
"amexApiRaw": item
}
}));
localStorage.setItem("amex-dining-merchants-"+country, JSON.stringify(merchantsJson));
} else {
merchantsJson = JSON.parse(cachedMerchantsData);
}
console.info("merchants for "+country+":", merchantsJson);
merchantsJson.forEach(item => {
if (!item.place) {
return;
}
new AdvancedMarkerElement({
map,
position: item.place.location,
title: item.place.name,
});
});
}

fillMarkers("DE");

}();
</script>

</body>
</html>

0 comments on commit 24f6587

Please sign in to comment.