0

I have two symptoms that make me think there's something wrong with my Nokia appId/token. One is that when I try to use the searchbox, I get a javascript error "Error 401 - Missing api_id". The second is when I go to developer.here.com and to My Apps, and look at the hit history of my app, I see zero hits. What am I doing wrong?

nokia.Settings.set("appId", "[My ID]");
nokia.Settings.set("authenticationToken", "[MY TOKEN]");

var my_lat = 41.88
var my_lon = -87.63

 map = new nokia.maps.map.Display(document.getElementById('mapcanvas'), {
     'components': [ 
            // Behavior collection
            new nokia.maps.map.component.Behavior(),
            new nokia.maps.map.component.ZoomBar(),
            new nokia.maps.map.component.Overview(),
            new nokia.maps.map.component.TypeSelector(),
            new nokia.maps.map.component.ScaleBar()
        ],
    'zoomLevel': 11, // Zoom level for the map


    'center': [my_lat, my_lon] // Center coordinates
});


// Initialize search box:
var searchBox = new nokia.places.widgets.SearchBox ({
    targetNode: 'searchbox',
    searchCenter: function () {
        return {
            latitude: my_lat,
            longitude: my_lon
        }
    },
    onResults: function (data) {
        renderResults (data);
    }
});

// Handle the results of the search. This callback function
// receives the raw places data as an array. For each element
// in this array, it creates an HTML list element and fills
// it with the name of the place:
function renderResults (data) {
    var previewList = document.getElementById ('results');
    previewList.innerHTML = '';

    var results = data.results.items;

    for (var i = 0, l = results.length; i < l; i++) {
        var result = results[i];
        var resultLi = document.createElement ('li');
        resultLi.innerHTML = result.title;
        previewList.appendChild (resultLi);
    }
}
Jason Fox
  • 5,115
  • 1
  • 15
  • 34
Corey Trager
  • 22,649
  • 18
  • 83
  • 121

2 Answers2

0

The problem was how I was getting the javascript lib.

This is what worked. Note the "with=maps,places".

<script type="text/javascript" src="http://api.maps.nokia.com/2.2.4/jsl.js?with=maps,places"></script>

Here's what did not work

<script type="text/javascript" src="http://api.maps.nokia.com/2.2.4/jsl.js"></script>
<script type="text/javascript" src="http://api.maps.nokia.com/2.2.4/jsl.js?with=places"></script>
Corey Trager
  • 22,649
  • 18
  • 83
  • 121
  • Looks like you discovered the answer yourself as I was typing it up- the reason behind this can be found in the API reference [documentation](http://developer.here.com/docs/maps_js/topics/overview.html#package-detection) - the places widget is not loaded by default. – Jason Fox Jun 06 '13 at 18:31
0

Your code looks correct - my assumption would be that the appId and token you are using are not valid.

Firstly to prove this is the case start with the code behind the Places Widget example. Copy the code to your PC or local server and see if you can get a local copy working for you - if you type the word Airport into the search box you should get suggestions appearing after the first three letters, and markers on the map once you click search.

Now try replacing the app id and token wih blanks:

nokia.Settings.set("appId", ""); 
nokia.Settings.set("authenticationToken", "");

The application should no longer work. If this is also the case when you enter your appId and token then it looks like you have incorrectly copied them, used the app name by mistake (or something is up with the back-end).

The most comprehensive guide to creating a new appId and token can be found here - I would follow it from scratch and create a new one if necessary. When logged in and you click on Manage Apps the appId and token can be found in the boxes on the right. Double click on the box to select all and ensure that you don't inadvertently miss the final character which may not quite fit in the box.

Go back to your working demo example and replace the demo appId and token with the ones associated with your account. Hopefully it should now work for you.

Jason Fox
  • 5,115
  • 1
  • 15
  • 34