HERE Maps Geocoder Autocomplete API CORS Errors
Я пытаюсь реализовать HERE Geocoder Autocomplete API на странице html, следуя примеру https://developer.here.com/documentation/examples/rest/geocoding_suggestions, в результате он показывает мне ошибку CORS. [показано на изображении][1].[1]: https://i.stack.imgur.com/O8duZ.png
var AUTOCOMPLETION_URL = 'https://autocomplete.geocoder.ls.hereapi.com/6.2/suggest.json',
ajaxRequest = new XMLHttpRequest(),
query = '';
/**
* If the text in the text box has changed, and is not empty,
* send a geocoding auto-completion request to the server.
*
* @param {Object} textBox the textBox DOM object linked to this event
* @param {Object} event the DOM event which fired this listener
*/
function autoCompleteListener(textBox, event) {
if (query != textBox.value) {
if (textBox.value.length >= 1) {
var params = '?' +
'query=' + encodeURIComponent(textBox.value) + // The search text which is the basis of the query
'&beginHighlight=' + encodeURIComponent('<mark>') + // Mark the beginning of the match in a token.
'&endHighlight=' + encodeURIComponent('</mark>') + // Mark the end of the match in a token.
'&maxresults=5' + // The upper limit the for number of suggestions to be included
// in the response. Default is set to 5.
'&apikey=' + APIKEY;
ajaxRequest.open('GET', AUTOCOMPLETION_URL + params);
ajaxRequest.send();
}
}
query = textBox.value;
}
function onAutoCompleteSuccess() {
clearOldSuggestions();
addSuggestionsToPanel(this.response); // In this context, 'this' means the XMLHttpRequest itself.
addSuggestionsToMap(this.response);
console.log(this.response);
}
function onAutoCompleteFailed() {
alert('Ooops!');
console.log(this.response);
}
var APIKEY = 'H6XyiCT0w1t9GgTjqhRXxDMrVj9h78ya3NuxlwM7XUs';
var platform = new H.service.Platform({
apikey: APIKEY,
useCIT: false,
useHTTPS: true
});
// Attach the event listeners to the XMLHttpRequest object
ajaxRequest.addEventListener("load", onAutoCompleteSuccess);
ajaxRequest.addEventListener("error", onAutoCompleteFailed);
ajaxRequest.responseType = "json";