Skip to content

Commit 703009f

Browse files
committed
Fix HERE Maps API example
1 parent 3913946 commit 703009f

File tree

4 files changed

+53
-38
lines changed

4 files changed

+53
-38
lines changed

.env.example

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ PINTEREST_SECRET=b32f578ad83d94c058c6682329220feda7e5817e043a1cc4a5a1e28f51c7030
6767

6868
GOOGLE_MAP_API_KEY=google-map-api-key
6969

70-
HERE_APP_ID=aHxxxxxxxxxxxxxxlIgc
71-
HERE_APP_CODE=9bxxxxxxxxxxxxxxxxJFHg
70+
HERE_API_KEY=9bxxxxxxxxxxxxxxxxJFHg
7271

7372
ALPHA_VANTAGE_KEY=api-key
7473

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,9 @@ Obtain SMTP credentials from a provider for transactional emails. Set the SMTP_U
261261
<img src="https://upload.wikimedia.org/wikipedia/commons/c/c7/HERE_logo.svg" height="75">
262262

263263
- Go to <a href="https://developer.here.com" target="_blank">https://developer.here.com</a>
264-
- Sign up and create a Freemium project
265-
- Create JAVASCRIPT/REST credentials. Copy and paste the APP_ID and APP into `.env` file.
266-
- Note that these credentials are available on the client-side, and you need to create a domain whitelist for your app credentials when you are publicly launching the app.
264+
- Sign up for the Base plan. The Base plan require a credit card to start, but you get 30,000 map renders for free each month.
265+
- Create JAVASCRIPT/REST credentials. Copy and paste the API key into the `.env` file as HERE_API_KEY, or set it up as an environment variable.
266+
- **Set up Trusted Domain** - Your credentials will go to the client-side (browser of the users). You need to enable trusted domains and add your test domain address. Otherwise, others may be able to use your credentials on other websites, go through your quota, and potentially leave you with a bill.
267267

268268
<hr>
269269

@@ -667,7 +667,7 @@ to create a flash message in your controllers, and then display them in your vie
667667
```pug
668668
if messages.errors
669669
.alert.alert-danger.fade.in
670-
for error in messages.errors
670+
each error in messages.errors
671671
div= error.msg
672672
```
673673

@@ -695,7 +695,7 @@ req.flash('warning', { msg: 'You have exceeded 90% of your data usage' });
695695
```pug
696696
if messages.warning
697697
.alert.alert-warning.fade.in
698-
for warning in messages.warning
698+
each warning in messages.warning
699699
div= warning.msg
700700
```
701701

@@ -705,13 +705,13 @@ The flash messages partial template is _included_ in the `layout.pug`, along wit
705705

706706
```pug
707707
body
708-
include partials/header
708+
include partials/header
709709
710-
.container
711-
include partials/flash
712-
block content
710+
.container
711+
include partials/flash
712+
block content
713713
714-
include partials/footer
714+
include partials/footer
715715
```
716716

717717
If you have any further questions about flash messages, please feel free to open an issue, and I will update this mini-guide accordingly, or send a pull request if you would like to include something that I missed.
@@ -821,7 +821,7 @@ block content
821821
h3 All Books
822822
823823
ul
824-
for book in books
824+
each book in books
825825
li= book.name
826826
```
827827

@@ -913,11 +913,11 @@ If you want to stick all your JavaScript inside templates, then in `layout.pug`
913913
```pug
914914
script(src='/socket.io/socket.io.js')
915915
script.
916-
let socket = io.connect(window.location.href);
917-
socket.on('greet', function (data) {
918-
console.log(data);
919-
socket.emit('respond', { message: 'Hey there, server!' });
920-
});
916+
let socket = io.connect(window.location.href);
917+
socket.on('greet', function (data) {
918+
console.log(data);
919+
socket.emit('respond', { message: 'Hey there, server!' });
920+
});
921921
```
922922
923923
**Note:** Notice the path of the `socket.io.js`, you don't actually have to have `socket.io.js` file anywhere in your project; it will be generated automatically at runtime.

controllers/api.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,8 +1106,7 @@ exports.postPinterest = (req, res, next) => {
11061106

11071107
exports.getHereMaps = (req, res) => {
11081108
res.render('api/here-maps', {
1109-
app_id: process.env.HERE_APP_ID,
1110-
app_code: process.env.HERE_APP_CODE,
1109+
apikey: process.env.HERE_API_KEY,
11111110
title: 'Here Maps API',
11121111
});
11131112
};

views/api/here-maps.pug

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,55 @@ block content
2121
#map(style='width: 100vw; height: 50vh')
2222

2323
div(style='display: flex; justify-content: center')
24-
| Straight line distance between the Fremont Troll and Seattle Art Museum is&nbsp
24+
| Straight line distance between the Fremont Troll and Seattle Art Museum is&nbsp;
2525
#directLineDistance
26-
| &nbspmiles.
26+
| &nbsp;miles.
27+
28+
script(src='https://js.api.here.com/v3/3.1/mapsjs-core.js', type='text/javascript', charset='utf-8')
29+
script(src='https://js.api.here.com/v3/3.1/mapsjs-service.js', type='text/javascript', charset='utf-8')
30+
script(src='https://js.api.here.com/v3/3.1/mapsjs-mapevents.js', type='text/javascript', charset='utf-8')
31+
script(src='https://js.api.here.com/v3/3.1/mapsjs-ui.js', type='text/javascript', charset='utf-8')
32+
link(rel='stylesheet', type='text/css', href='https://js.api.here.com/v3/3.1/mapsjs-ui.css')
2733

28-
script(src='https://js.api.here.com/v3/3.0/mapsjs-core.js', type='text/javascript', charset='utf-8')
29-
script(src='https://js.api.here.com/v3/3.0/mapsjs-service.js', type='text/javascript', charset='utf-8')
30-
script(src='https://js.api.here.com/v3/3.0/mapsjs-mapevents.js', type='text/javascript', charset='utf-8')
3134
script.
3235
const platform = new H.service.Platform({
3336
useHTTPS: true,
34-
app_id: '#{app_id}',
35-
app_code: '#{app_code}',
37+
apikey: '#{apikey}',
38+
});
39+
40+
const defaultLayers = platform.createDefaultLayers();
41+
const map = new H.Map(document.getElementById('map'), defaultLayers.vector.normal.map, {
42+
zoom: 12,
43+
center: { lat: 47.6573676, lng: -122.3126527 },
3644
});
37-
const map = new H.Map(document.getElementById('map'), platform.createDefaultLayers().normal.map, { zoom: 12, center: { lat: 47.6573676, lng: -122.3126527 } });
45+
3846
const mapEvents = new H.mapevents.MapEvents(map);
39-
// at this point the map is rendered, lets add some markers
4047
const behavior = new H.mapevents.Behavior(mapEvents);
48+
49+
// Create markers
4150
const marker1 = new H.map.Marker({ lat: 47.6516216, lng: -122.3498897 });
4251
const marker2 = new H.map.Marker({ lat: 47.6123335, lng: -122.3314332 });
4352
const marker3 = new H.map.Marker({ lat: 47.6162956, lng: -122.3555097 });
4453
const marker4 = new H.map.Marker({ lat: 47.6205099, lng: -122.3514661 });
4554

55+
// Create line string for polygon
4656
const lineString = new H.geo.LineString();
47-
lineString.pushPoint(marker1.getPosition());
48-
lineString.pushPoint(marker2.getPosition());
49-
lineString.pushPoint(marker3.getPosition());
50-
lineString.pushPoint(marker4.getPosition());
57+
lineString.pushLatLngAlt(47.6516216, -122.3498897);
58+
lineString.pushLatLngAlt(47.6123335, -122.3314332);
59+
lineString.pushLatLngAlt(47.6162956, -122.3555097);
60+
lineString.pushLatLngAlt(47.6205099, -122.3514661);
61+
62+
// Create polygon
63+
const polygon = new H.map.Polygon(lineString, { style: { lineWidth: 2, strokeColor: 'black', fillColor: 'rgba(255, 0, 255, 0.5)' } });
64+
65+
// Create circle
66+
const circle = new H.map.Circle({ lat: 47.6205099, lng: -122.3514661 }, 3000, { style: { strokeColor: 'rgba(0,128,0, 0.6)', lineWidth: 1, fillColor: 'rgba(0, 128, 0, 0.3)' } });
5167

52-
const polygon = new H.map.Polygon(lineString, { style: { strokeColor: 'black', lineWidth: 2, fillColor: 'rgba(255, 0, 255, 0.5)' } });
53-
const circle = new H.map.Circle(marker4.getPosition(), 1500, { style: { strokeColor: 'rgba(0,128,0, 0.6)', lineWidth: 1, fillColor: 'rgba(0, 128, 0, 0.3)' } });
68+
// Add all objects to the map
5469
map.addObjects([marker1, marker2, marker3, marker4, polygon, circle]);
55-
// At this point we have rendered all of the markers, the polygon and the circle that were set in the prior lines
5670

57-
const distance = (marker1.getPosition().distance(marker2.getPosition()) / 1609.344).toFixed(2);
58-
directLineDistance.innerHTML = distance;
71+
// Calculate distance
72+
const start = marker1.getGeometry();
73+
const end = marker2.getGeometry();
74+
const distance = (start.distance(end) / 1609.344).toFixed(2);
75+
document.getElementById('directLineDistance').innerHTML = distance;

0 commit comments

Comments
 (0)