Skip to content

Commit 42302e4

Browse files
authored
Merge pull request #92 from kplotnik/master
Changed Geocoding examples to use Geocoder & Search v7
2 parents b0a4c54 + 21b6155 commit 42302e4

File tree

8 files changed

+102
-128
lines changed

8 files changed

+102
-128
lines changed

geocode-a-location-from-address/demo.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ <h1>Search for a Location based on an Address</h1>
2626
<div id="panel"></div>
2727
<h3>Code</h3>
2828
<p>Access to the geocoding service is obtained from the <code>H.service.Platform</code>
29-
by calling <code>getGeocodingService()</code>. The <code>geocode()</code> method is used
30-
to find a location by passing in the relevant <code>searchtext</code> parameter as defined in
31-
<a href="http://developer.here.com/rest-apis/documentation/geocoder/topics/resource-search.html" target="_blank">Geocoder API</a>.
29+
by calling <code>getSearchService()</code>. The <code>geocode()</code> method is used
30+
to find a location by passing in the relevant <code>q</code> parameter as defined in
31+
<a href="https://developer.here.com/documentation/geocoding-search-api/dev_guide/topics/endpoint-geocode-brief.html" target="_blank">Geocoding and Search API v7</a>.
3232
The styling and display of the response is under the control of the developer.</p>
3333
<script type="text/javascript" src='demo.js'></script>
3434
</body>

geocode-a-location-from-address/demo.js

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
* @param {H.service.Platform} platform A stub class to access HERE services
1010
*/
1111
function geocode(platform) {
12-
var geocoder = platform.getGeocodingService(),
13-
geocodingParameters = {
14-
searchText: '200 S Mathilda Sunnyvale CA',
15-
jsonattributes : 1
16-
};
12+
var geocoder = platform.getSearchService(),
13+
geocodingParameters = {
14+
q: '200 S Mathilda Sunnyvale CA'
15+
};
1716

1817
geocoder.geocode(
1918
geocodingParameters,
@@ -28,7 +27,7 @@ function geocode(platform) {
2827
* see: http://developer.here.com/rest-apis/documentation/geocoder/topics/resource-type-response-geocode.html
2928
*/
3029
function onSuccess(result) {
31-
var locations = result.response.view[0].result;
30+
var locations = result.items;
3231
/*
3332
* The styling of the geocoding response on the map is entirely under the developer's control.
3433
* A representitive styling can be found the full JS + HTML code of this example
@@ -107,33 +106,31 @@ function openBubble(position, text){
107106
function addLocationsToPanel(locations){
108107

109108
var nodeOL = document.createElement('ul'),
110-
i;
109+
i;
111110

112111
nodeOL.style.fontSize = 'small';
113112
nodeOL.style.marginLeft ='5%';
114113
nodeOL.style.marginRight ='5%';
115114

116115

117116
for (i = 0; i < locations.length; i += 1) {
117+
let location = locations[i];
118118
var li = document.createElement('li'),
119-
divLabel = document.createElement('div'),
120-
address = locations[i].location.address,
121-
content = '<strong style="font-size: large;">' + address.label + '</strong></br>';
122-
position = {
123-
lat: locations[i].location.displayPosition.latitude,
124-
lng: locations[i].location.displayPosition.longitude
125-
};
119+
divLabel = document.createElement('div'),
120+
address = location.address,
121+
content = '<strong style="font-size: large;">' + address.label + '</strong></br>';
122+
position = location.position;
126123

127124
content += '<strong>houseNumber:</strong> ' + address.houseNumber + '<br/>';
128125
content += '<strong>street:</strong> ' + address.street + '<br/>';
129126
content += '<strong>district:</strong> ' + address.district + '<br/>';
130127
content += '<strong>city:</strong> ' + address.city + '<br/>';
131128
content += '<strong>postalCode:</strong> ' + address.postalCode + '<br/>';
132129
content += '<strong>county:</strong> ' + address.county + '<br/>';
133-
content += '<strong>country:</strong> ' + address.country + '<br/>';
134-
content += '<br/><strong>position:</strong> ' +
130+
content += '<strong>country:</strong> ' + address.countryName + '<br/>';
131+
content += '<strong>position:</strong> ' +
135132
Math.abs(position.lat.toFixed(4)) + ((position.lat > 0) ? 'N' : 'S') +
136-
' ' + Math.abs(position.lng.toFixed(4)) + ((position.lng > 0) ? 'E' : 'W');
133+
' ' + Math.abs(position.lng.toFixed(4)) + ((position.lng > 0) ? 'E' : 'W') + '<br/>';
137134

138135
divLabel.innerHTML = content;
139136
li.appendChild(divLabel);
@@ -151,18 +148,16 @@ function addLocationsToPanel(locations){
151148
* H.service.GeocodingService
152149
*/
153150
function addLocationsToMap(locations){
151+
debugger
154152
var group = new H.map.Group(),
155-
position,
156-
i;
153+
position,
154+
i;
157155

158156
// Add a marker for each location found
159157
for (i = 0; i < locations.length; i += 1) {
160-
position = {
161-
lat: locations[i].location.displayPosition.latitude,
162-
lng: locations[i].location.displayPosition.longitude
163-
};
164-
marker = new H.map.Marker(position);
165-
marker.label = locations[i].location.address.label;
158+
let location = locations[i];
159+
marker = new H.map.Marker(location.position);
160+
marker.label = location.address.label;
166161
group.addObject(marker);
167162
}
168163

geocode-a-location-from-structured-address/demo.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ <h1>Search for a Location given a Structured Address</h1>
2626
<div id="panel"></div>
2727
<h3>Code</h3>
2828
<p>Access to the geocoding service is obtained from the <code>H.service.Platform</code>
29-
by calling <code>getGeocodingService()</code>. The <code>geocode()</code> method is used
30-
to find a location by passing in the relevant parameters (i.e. <code>country</code>, <code>city</code>,
31-
<code>street</code> and <code>housenumber</code>) as defined in
32-
<a href="http://developer.here.com/rest-apis/documentation/geocoder/topics/resource-search.html" target="_blank">Geocoder API</a>.
29+
by calling <code>getSearchService()</code>. The <code>geocode()</code> method is used
30+
to find a location by passing in the relevant values to the <code>qq</code> parameter (i.e. <code>country</code>, <code>city</code>,
31+
<code>street</code> and <code>housenumber</code>) as defined in
32+
<a href="https://developer.here.com/documentation/geocoding-search-api/dev_guide/topics/endpoint-geocode-brief.html" target="_blank">Geocoding and Search API v7
33+
</a>.
3334
The styling and display of the response is under the control of the developer.</p>
3435
<script type="text/javascript" src='demo.js'></script>
3536
</body>

geocode-a-location-from-structured-address/demo.js

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@
99
* @param {H.service.Platform} platform A stub class to access HERE services
1010
*/
1111
function geocode(platform) {
12-
var geocoder = platform.getGeocodingService(),
13-
geocodingParameters = {
14-
housenumber: '425',
15-
street: 'randolph',
16-
city: 'chicago',
17-
country: 'usa',
18-
jsonattributes : 1
19-
};
12+
var geocoder = platform.getSearchService(),
13+
geocodingParameters = {
14+
qq: 'houseNumber=425;street=randolph;city=chicago;country=usa'
15+
};
2016

2117
geocoder.geocode(
2218
geocodingParameters,
@@ -31,7 +27,7 @@ function geocode(platform) {
3127
* see: http://developer.here.com/rest-apis/documentation/geocoder/topics/resource-type-response-geocode.html
3228
*/
3329
function onSuccess(result) {
34-
var locations = result.response.view[0].result;
30+
var locations = result.items;
3531
/*
3632
* The styling of the geocoding response on the map is entirely under the developer's control.
3733
* A representitive styling can be found the full JS + HTML code of this example
@@ -110,33 +106,30 @@ function openBubble(position, text){
110106
function addLocationsToPanel(locations){
111107

112108
var nodeOL = document.createElement('ul'),
113-
i;
109+
i;
114110

115111
nodeOL.style.fontSize = 'small';
116112
nodeOL.style.marginLeft ='5%';
117113
nodeOL.style.marginRight ='5%';
118114

119-
120-
for (i = 0; i < locations.length; i += 1) {
121-
var li = document.createElement('li'),
115+
for (i = 0; i < locations.length; i += 1) {
116+
let location = locations[i],
117+
li = document.createElement('li'),
122118
divLabel = document.createElement('div'),
123-
address = locations[i].location.address,
119+
address = location.address,
124120
content = '<strong style="font-size: large;">' + address.label + '</strong></br>';
125-
position = {
126-
lat: locations[i].location.displayPosition.latitude,
127-
lng: locations[i].location.displayPosition.longitude
128-
};
121+
position = location.position;
129122

130123
content += '<strong>houseNumber:</strong> ' + address.houseNumber + '<br/>';
131124
content += '<strong>street:</strong> ' + address.street + '<br/>';
132125
content += '<strong>district:</strong> ' + address.district + '<br/>';
133126
content += '<strong>city:</strong> ' + address.city + '<br/>';
134127
content += '<strong>postalCode:</strong> ' + address.postalCode + '<br/>';
135128
content += '<strong>county:</strong> ' + address.county + '<br/>';
136-
content += '<strong>country:</strong> ' + address.country + '<br/>';
137-
content += '<br/><strong>position:</strong> ' +
129+
content += '<strong>country:</strong> ' + address.countryName + '<br/>';
130+
content += '<strong>position:</strong> ' +
138131
Math.abs(position.lat.toFixed(4)) + ((position.lat > 0) ? 'N' : 'S') +
139-
' ' + Math.abs(position.lng.toFixed(4)) + ((position.lng > 0) ? 'E' : 'W');
132+
' ' + Math.abs(position.lng.toFixed(4)) + ((position.lng > 0) ? 'E' : 'W') + '<br/>';
140133

141134
divLabel.innerHTML = content;
142135
li.appendChild(divLabel);
@@ -155,17 +148,14 @@ function addLocationsToPanel(locations){
155148
*/
156149
function addLocationsToMap(locations){
157150
var group = new H.map.Group(),
158-
position,
159-
i;
151+
position,
152+
i;
160153

161154
// Add a marker for each location found
162155
for (i = 0; i < locations.length; i += 1) {
163-
position = {
164-
lat: locations[i].location.displayPosition.latitude,
165-
lng: locations[i].location.displayPosition.longitude
166-
};
167-
marker = new H.map.Marker(position);
168-
marker.label = locations[i].location.address.label;
156+
let location = locations[i];
157+
marker = new H.map.Marker(location.position);
158+
marker.label = location.address.label;
169159
group.addObject(marker);
170160
}
171161

reverse-geocode-an-address-from-location/demo.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ <h1>Search for the Address of a Known Location</h1>
2727
<div id="panel"></div>
2828
<h3>Code</h3>
2929
<p>Access to the geocoding service is obtained from the <code>H.service.Platform</code>
30-
by calling <code>getGeocodingService()</code>. The <code>reverseGeocode()</code> method is used
30+
by calling <code>getSearchService()</code>. The <code>reverseGeocode()</code> method is used
3131
to find a location by passing in the relevant parameters (such as <code>prox</code> and <code>maxresults</code>) as defined in
32-
<a href="http://developer.here.com/rest-apis/documentation/geocoder/topics/resource-search.html" target="_blank">Geocoder API</a>.
32+
<a href="https://developer.here.com/documentation/geocoding-search-api/dev_guide/topics/endpoint-reverse-geocode-brief.html" target="_blank">Geocoding and Search API v7
33+
</a>.
3334
The styling and display of the response is under the control of the developer.</p>
3435
<script type="text/javascript" src='demo.js'></script>
3536
</body>

reverse-geocode-an-address-from-location/demo.js

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@
1111
* @param {H.service.Platform} platform A stub class to access HERE services
1212
*/
1313
function reverseGeocode(platform) {
14-
var geocoder = platform.getGeocodingService(),
15-
reverseGeocodingParameters = {
16-
prox: '52.5309,13.3847,150', // Berlin
17-
mode: 'retrieveAddresses',
18-
maxresults: '1',
19-
jsonattributes : 1
20-
};
14+
var geocoder = platform.getSearchService(),
15+
reverseGeocodingParameters = {
16+
at: '52.5309,13.3847,150', // Berlin
17+
limit: '1'
18+
};
2119

2220
geocoder.reverseGeocode(
2321
reverseGeocodingParameters,
@@ -33,7 +31,7 @@ function reverseGeocode(platform) {
3331
* see: http://developer.here.com/rest-apis/documentation/geocoder/topics/resource-type-response-geocode.html
3432
*/
3533
function onSuccess(result) {
36-
var locations = result.response.view[0].result;
34+
var locations = result.items;
3735
/*
3836
* The styling of the geocoding response on the map is entirely under the developer's control.
3937
* A representitive styling can be found the full JS + HTML code of this example
@@ -112,33 +110,30 @@ function openBubble(position, text){
112110
function addLocationsToPanel(locations){
113111

114112
var nodeOL = document.createElement('ul'),
115-
i;
113+
i;
116114

117115
nodeOL.style.fontSize = 'small';
118116
nodeOL.style.marginLeft ='5%';
119117
nodeOL.style.marginRight ='5%';
120118

121-
122-
for (i = 0; i < locations.length; i += 1) {
123-
var li = document.createElement('li'),
119+
for (i = 0; i < locations.length; i += 1) {
120+
let location = locations[i],
121+
li = document.createElement('li'),
124122
divLabel = document.createElement('div'),
125-
address = locations[i].location.address,
123+
address = location.address,
126124
content = '<strong style="font-size: large;">' + address.label + '</strong></br>';
127-
position = {
128-
lat: locations[i].location.displayPosition.latitude,
129-
lng: locations[i].location.displayPosition.longitude
130-
};
125+
position = location.position;
131126

132127
content += '<strong>houseNumber:</strong> ' + address.houseNumber + '<br/>';
133128
content += '<strong>street:</strong> ' + address.street + '<br/>';
134129
content += '<strong>district:</strong> ' + address.district + '<br/>';
135130
content += '<strong>city:</strong> ' + address.city + '<br/>';
136131
content += '<strong>postalCode:</strong> ' + address.postalCode + '<br/>';
137132
content += '<strong>county:</strong> ' + address.county + '<br/>';
138-
content += '<strong>country:</strong> ' + address.country + '<br/>';
139-
content += '<br/><strong>position:</strong> ' +
133+
content += '<strong>country:</strong> ' + address.countryName + '<br/>';
134+
content += '<strong>position:</strong> ' +
140135
Math.abs(position.lat.toFixed(4)) + ((position.lat > 0) ? 'N' : 'S') +
141-
' ' + Math.abs(position.lng.toFixed(4)) + ((position.lng > 0) ? 'E' : 'W');
136+
' ' + Math.abs(position.lng.toFixed(4)) + ((position.lng > 0) ? 'E' : 'W') + '<br/>';
142137

143138
divLabel.innerHTML = content;
144139
li.appendChild(divLabel);
@@ -157,17 +152,14 @@ function addLocationsToPanel(locations){
157152
*/
158153
function addLocationsToMap(locations){
159154
var group = new H.map.Group(),
160-
position,
161-
i;
155+
position,
156+
i;
162157

163158
// Add a marker for each location found
164159
for (i = 0; i < locations.length; i += 1) {
165-
position = {
166-
lat: locations[i].location.displayPosition.latitude,
167-
lng: locations[i].location.displayPosition.longitude
168-
};
169-
marker = new H.map.Marker(position);
170-
marker.label = locations[i].location.address.label;
160+
let location = locations[i];
161+
marker = new H.map.Marker(location.position);
162+
marker.label = location.address.label;
171163
group.addObject(marker);
172164
}
173165

search-for-landmark/demo.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ <h1>Search for a Landmark</h1>
2626
<div id="panel"></div>
2727
<h3>Code</h3>
2828
<p>Access to the geocoding service is obtained from the <code>H.service.Platform</code>
29-
by calling <code>getGeocodingService()</code>. The <code>search()</code> method is used
29+
by calling <code>getGeocodingService()</code>. The <code>discover()</code> method is used
3030
to find a landmark by passing in the relevant parameters as defined in
31-
<a href="http://developer.here.com/rest-apis/documentation/geocoder/topics/resource-search.html" target="_blank">Geocoder API</a>.
31+
<a href="https://developer.here.com/documentation/geocoding-search-api/dev_guide/topics/endpoint-discover-brief.html" target="_blank">Geocoding and Search API v7
32+
</a>.
3233
The styling and display of the response is under the control of the developer.</p>
3334
<script type="text/javascript" src='demo.js'></script>
3435
</body>

0 commit comments

Comments
 (0)