Reputation: 3275
I am trying to use the api of Here Maps version 3.1, especially the geocoding service.
I have followed the steps to have an api key, and then I tried to have access to the geocoder service using the example code of the documentation.
I replaced {YOUR_API_KEY}
by my new apikey, and put the example code into a fresh index.html file :
<html>
<head>
<script
src="https://js.api.here.com/v3/3.1/mapsjs-core.js"
type="text/javascript"
charset="utf-8"
></script>
<script
src="https://js.api.here.com/v3/3.1/mapsjs-service.js"
type="text/javascript"
charset="utf-8"
></script>
</head>
<body>
<div id="mapContainer"></div>
<script>
// Instantiate a map and platform object:
var platform = new H.service.Platform({
apikey: "MY_API_KEY"
});
// Retrieve the target element for the map:
var targetElement = document.getElementById("mapContainer");
// Get default map types from the platform object:
var defaultLayers = platform.createDefaultLayers();
// Instantiate the map:
var map = new H.Map(
document.getElementById("mapContainer"),
defaultLayers.vector.normal.map,
{
zoom: 10,
center: { lat: 52.51, lng: 13.4 }
}
);
// Create the parameters for the geocoding request:
var geocodingParams = {
searchText: "200 S Mathilda Ave, Sunnyvale, CA"
};
// Define a callback function to process the geocoding response:
var onResult = function(result) {
var locations = result.Response.View[0].Result,
position,
marker;
// Add a marker for each location found
for (i = 0; i < locations.length; i++) {
position = {
lat: locations[i].Location.DisplayPosition.Latitude,
lng: locations[i].Location.DisplayPosition.Longitude
};
marker = new H.map.Marker(position);
map.addObject(marker);
}
};
// Get an instance of the geocoding service:
var geocoder = platform.getGeocodingService();
// Call the geocode method with the geocoding parameters,
// the callback and an error callback function (called if a
// communication error occurs):
geocoder.geocode(geocodingParams, onResult, function(e) {
alert(e);
});
</script>
<style>
#mapContainer {
width: 100%;
height: 300px;
}
</style>
</body>
</html>
When I open this file in my browser I can see the map with city names and everything so I think I have permission to access the map api, but the geocode service fails with a 401 error : {"error":"Unauthorized","error_description":"ApiKey invalid. ApiKey not found."}
But my apikey is enabled in my project page, I have checked and i didn't mispell the apikey (i copied/pasted it many times to be sure).
Do you have any suggestion ?
Thank you.
Upvotes: 1
Views: 2131
Reputation: 161
Same issue for me. Then I created a new API key, and it's working with this one. Seems like a problem on HERE's end.
Upvotes: 0
Reputation:
While adding ApiKey always keep in mind to remove extra space before and after the key and also remove the {}.
https://developer.here.com/documentation/maps/dev_guide/topics/geocoding.html
Upvotes: 1