×
Namespaces

Variants
Actions
(Difference between revisions)

HERE Maps API - getting and setting the default language in application context

From Nokia Developer Wiki
Jump to: navigation, search
jasfox (Talk | contribs)
m (Jasfox - Add link.)
jasfox (Talk | contribs)
m (Jasfox - Updated example to use Nokia Maps API 2.2)
Line 8: Line 8:
 
|platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
 
|platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
|dependencies=Nokia Maps 2.1.0
+
|dependencies=Nokia Maps 2.2.0
 
|signing=<!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 
|signing=<!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 
|capabilities=<!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 
|capabilities=<!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
Line 31: Line 31:
 
==Important about Maps credentials==   
 
==Important about Maps credentials==   
  
With Nokia Maps API you can start without having any credentials given, but you might face a performance gap. In order to get the full potential out of the  offering, you must get the credentials that authenticate your application against the Services. Please read through the Location API.  For more information on how to obtain the credentials, please start with the  Nokia Maps API Developers Guide section "Acquiring API credentials".   
+
From version 2.2 of the [http://api.maps.nokia.com/ Nokia Maps API] onwards, authentication credentials are required to use the Nokia Maps API servcies. If you start without having any credentials, a map may not be displayed. In order to get the full potential out of the  offering, you must get the credentials that authenticate your application against the Services. Please read through the Location API.  For more information on how to obtain the credentials, please start with the  Nokia Maps API Developers Guide section "Acquiring API credentials".   
  
 
==Implementation==   
 
==Implementation==   
  
This is a full HTML & JavaScript example. Feel free to modify and use for your own purposes.
+
This is a full HTML & JavaScript example. Add in your own [http://api.developer.nokia.com/ AppId and Token] and feel free to modify and use for your own purposes.
 
+
  
 
<code javascript>
 
<code javascript>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
 
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
+
<head>
<meta http-equiv="content-type" content= "text/html; charset=us-ascii" />
+
<meta http-equiv="content-type" content=
        <meta http-equiv="X-UA-Compatible" content="IE=7; IE=EmulateIE9" />
+
"text/html; charset=us-ascii" />
        <title>Setting the map language</title>
+
<meta http-equiv="X-UA-Compatible" content="IE=7; IE=EmulateIE9" />
        <!-- By default we add ?kml=auto&heatmap=auto to auto load KML & heatmap package remove params if package are not needed -->
+
<title>Setting the map language</title>
        <script type="text/javascript" charset="UTF-8" src="http://api.maps.nokia.com/2.1.0/jsl.js?kml=auto&amp;heatmap=auto">
+
<!-- This file loads up a map of Europe and displays it in a variety of languages.  -->
        </script>
+
<!-- No additional support is required here, just load basic capabilities -->
  </head>
+
<script type="text/javascript" charset="UTF-8" src="http://api.maps.nokia.com/2.2.0/jsl.js"></script>
  <body>
+
</head>
      <div id="mapContainer" style= "z-index: -1; left:0px; top:0px; width: 50%; height: 50%; position: absolute;">
+
<body>
      </div>
+
<div id="mapContainer" style=
      <script type="text/javascript">
+
"z-index: -1; left:0px; top:0px; width: 50%; height: 50%; position: absolute;">
//<![CDATA[                          
+
</div>
            var appContext = nokia.maps.util.ApplicationContext;  
+
<script type="text/javascript">
            // Go thru all the language options  
+
//<![CDATA[                  
            var availableLanguages = ["en-US", "en-GB", "de-DE", "es-ES", "fr-FR", "it-IT", "ru-RU", "zh-CN"]  
+
/////////////////////////////////////////////////////////////////////////////////////
          //get a random language  
+
// Don't forget to set your API credentials
          var randomLanguageIndex = Math.floor(Math.random() * availableLanguages.length); var randomLanguage = availableLanguages[randomLanguageIndex];  
+
//
          // Get and store the current map default language  
+
// Replace with your appId and token which you can obtain when you
          var currentLanguage = appContext.get("defaultLanguage");  
+
// register on http://api.developer.nokia.com/
          // Display a note to the user within the document  
+
//
          document.write("The Initial Default Language is " + currentLanguage);  
+
nokia.Settings.set( "appId", "YOUR APP ID GOES HERE");
          // Write line break  
+
nokia.Settings.set( "authenticationToken", "YOUR AUTHENTICATION TOKEN GOES HERE");
          document.write("<br />");  
+
//
          // Set the default language of the map  
+
//////////////////////////////
          appContext.set("defaultLanguage", randomLanguage);  
+
/*]]>*/       
          // Get the new language we have just set  
+
</script>
          currentLanguage = appContext.get("defaultLanguage");  
+
 
          // Write the new language  
+
<script type="text/javascript">     
          document.write("Now the Default Language is " + currentLanguage);  
+
var appContext = nokia.maps.util.ApplicationContext;  
 +
// Go thru all the language options  
 +
var availableLanguages = ["en-US", "en-GB", "de-DE", "es-ES", "fr-FR", "it-IT", "ru-RU", "zh-CN"]  
 +
//get a random language  
 +
var randomLanguageIndex = Math.floor(Math.random() * availableLanguages.length); var randomLanguage = availableLanguages[randomLanguageIndex];  
 +
// Get and store the current map default language  
 +
var currentLanguage = appContext.get("defaultLanguage");  
 +
// Display a note to the user within the document  
 +
document.write("The Initial Default Language is " + currentLanguage);  
 +
// Write line break  
 +
document.write("<br />");  
 +
// Set the default language of the map  
 +
appContext.set("defaultLanguage", randomLanguage);  
 +
// Get the language we have just set  
 +
currentLanguage = appContext.get("defaultLanguage");  
 +
// Write the new language  
 +
document.write("Now the Default Language is " + currentLanguage);  
  
          // Get the DOM node to which we will append the map
+
// Get the DOM node to which we will append the map
        var mapContainer = document.getElementById("mapContainer");
+
var mapContainer = document.getElementById("mapContainer");
  
        // Define the Nokia Maps  
+
// Define the Nokia Maps  
        var map = new nokia.maps.map.Display(mapContainer, {
+
var map = new nokia.maps.map.Display(mapContainer, {
 
         // initial center and zoom level of the map
 
         // initial center and zoom level of the map
            center: [53.1, 13.1],
+
        center: [53.1, 13.1],
            zoomLevel: 4,
+
        zoomLevel: 4,
            components: [
+
        components: [
 
                 new nokia.maps.map.component.ZoomBar(),  
 
                 new nokia.maps.map.component.ZoomBar(),  
 
                 new nokia.maps.map.component.Behavior(),
 
                 new nokia.maps.map.component.Behavior(),
Line 88: Line 103:
 
                 new nokia.maps.map.component.Overview(),
 
                 new nokia.maps.map.component.Overview(),
 
                 new nokia.maps.map.component.ScaleBar(),
 
                 new nokia.maps.map.component.ScaleBar(),
                 new nokia.maps.positioning.component.Positioning(),
+
                 new nokia.maps.positioning.component.Positioning()
                new nokia.maps.map.component.RightClick(),
+
                new nokia.maps.search.component.RightClick(),
+
                new nokia.maps.routing.component.RightClick()
+
 
         ]
 
         ]
    });
+
});
 
//]]>
 
//]]>
    </script>  
+
</script>  
  </body>  
+
</body>  
 
</html>
 
</html>
 
</code>
 
</code>

Revision as of 14:30, 10 April 2012

This articles shows how to get and set the default language in application context.

Article Metadata
Dependencies: Nokia Maps 2.2.0
Article
Created: Maveric (25 Oct 2011)
Last edited: jasfox (10 Apr 2012)

Contents

Prerequisites

Nokia Maps API supported web browser (basically any modern web browser)

Important about Maps credentials

From version 2.2 of the Nokia Maps API onwards, authentication credentials are required to use the Nokia Maps API servcies. If you start without having any credentials, a map may not be displayed. In order to get the full potential out of the offering, you must get the credentials that authenticate your application against the Services. Please read through the Location API. For more information on how to obtain the credentials, please start with the Nokia Maps API Developers Guide section "Acquiring API credentials".

Implementation

This is a full HTML & JavaScript example. Add in your own AppId and Token and feel free to modify and use for your own purposes.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content=
"text/html; charset=us-ascii" />
<meta http-equiv="X-UA-Compatible" content="IE=7; IE=EmulateIE9" />
<title>Setting the map language</title>
<!-- This file loads up a map of Europe and displays it in a variety of languages. -->
<!-- No additional support is required here, just load basic capabilities -->
<script type="text/javascript" charset="UTF-8" src="http://api.maps.nokia.com/2.2.0/jsl.js"></script>
</head>
<body>
<div id="mapContainer" style=
"z-index: -1; left:0px; top:0px; width: 50%; height: 50%; position: absolute;">
</div>
<script type="text/javascript">
//<![CDATA[
/////////////////////////////////////////////////////////////////////////////////////
// Don't forget to set your API credentials
//
// Replace with your appId and token which you can obtain when you
// register on http://api.developer.nokia.com/
//
nokia.Settings.set( "appId", "YOUR APP ID GOES HERE");
nokia.Settings.set( "authenticationToken", "YOUR AUTHENTICATION TOKEN GOES HERE");
//
//////////////////////////////
/*]]>*/
</script>
 
<script type="text/javascript">
var appContext = nokia.maps.util.ApplicationContext;
// Go thru all the language options
var availableLanguages = ["en-US", "en-GB", "de-DE", "es-ES", "fr-FR", "it-IT", "ru-RU", "zh-CN"]
//get a random language
var randomLanguageIndex = Math.floor(Math.random() * availableLanguages.length); var randomLanguage = availableLanguages[randomLanguageIndex];
// Get and store the current map default language
var currentLanguage = appContext.get("defaultLanguage");
// Display a note to the user within the document
document.write("The Initial Default Language is " + currentLanguage);
// Write line break
document.write("<br />");
// Set the default language of the map
appContext.set("defaultLanguage", randomLanguage);
// Get the language we have just set
currentLanguage = appContext.get("defaultLanguage");
// Write the new language
document.write("Now the Default Language is " + currentLanguage);
 
// Get the DOM node to which we will append the map
var mapContainer = document.getElementById("mapContainer");
 
// Define the Nokia Maps
var map = new nokia.maps.map.Display(mapContainer, {
// initial center and zoom level of the map
center: [53.1, 13.1],
zoomLevel: 4,
components: [
new nokia.maps.map.component.ZoomBar(),
new nokia.maps.map.component.Behavior(),
new nokia.maps.map.component.TypeSelector(),
new nokia.maps.map.component.Traffic(),
new nokia.maps.map.component.PublicTransport(),
new nokia.maps.map.component.Overview(),
new nokia.maps.map.component.ScaleBar(),
new nokia.maps.positioning.component.Positioning()
]
});
//]]>
</script>
</body>
</html>

Tested with

Mozilla FireFox 8.0 Google Chrome 14.0.835.202 m

229 page views in the last 30 days.
×