×
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 - Corrected Category)
jasfox (Talk | contribs)
m (Jasfox - Swithc to Nokia Maps example.)
Line 21: Line 21:
 
|author=[[User:Maveric]]
 
|author=[[User:Maveric]]
 
}}
 
}}
 +
{{SeeAlso|
 +
*  [http://api.maps.nokia.com/ Nokia Maps API]  }}
  
 
==Prerequisites==   
 
==Prerequisites==   
Line 35: Line 37:
  
  
<code java>
+
<code javascript>
<html>  
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<head>   
+
<html xmlns="http://www.w3.org/1999/xhtml">
<script src="http://api.maps.ovi.com/jsl.js" type="text/javascript" charset="utf-8"></script>    
+
  <head>
<link rel="stylesheet" href="style.css" />
+
<meta http-equiv="content-type" content= "text/html; charset=us-ascii" />
</head>
+
        <meta http-equiv="X-UA-Compatible" content="IE=7; IE=EmulateIE9" />
<div id="map" style="width:100%; height:80%;"></div>  
+
        <title>Setting the map language</title>
<body style = "width:80%; height:80%;"></div>  
+
        <!-- By default we add ?kml=auto&heatmap=auto to auto load KML & heatmap package remove params if package are not needed -->
</body>
+
        <script type="text/javascript" charset="UTF-8" src="http://api.maps.nokia.com/2.1.0/jsl.js?kml=auto&amp;heatmap=auto">
<script type="text/javascript">  
+
        </script>
// Define the Nokia Maps
+
  </head>
var map= new ovi.mapsapi.map.Display(document.getElementById("map"),   // new instance of Nokia Maps {   
+
  <body>
           components: [ new ovi.mapsapi.map.component.Behavior(),               
+
      <div id="mapContainer" style= "z-index: -1; left:0px; top:0px; width: 50%; height: 50%; position: absolute;">
                        new ovi.mapsapi.map.component.ZoomBar(),               
+
      </div>
                        new ovi.mapsapi.map.component.Overview(),               
+
      <script type="text/javascript">
                        new ovi.mapsapi.map.component.TypeSelector(),                
+
//<![CDATA[                         
                        new ovi.mapsapi.map.component.ScaleBar()],
+
            var appContext = nokia.maps.util.ApplicationContext;
                            'zoomLevel': 4,
+
            // Go thru all the language options
                            'center':[53.1, 13.1] });  
+
            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 new language we have just set
 +
          currentLanguage = appContext.get("defaultLanguage");
 +
          // Write the new language
 +
          document.write("Now the Default Language is " + currentLanguage);  
  
var appContext = ovi.mapsapi.util.ApplicationContext;
+
          // Get the DOM node to which we will append the map
// Go thru all the language options
+
        var mapContainer = document.getElementById("mapContainer");
var availableLanguages = ["en-US", "en-GB", "de-DE", "es-ES", "fr-FR", "it-IT", "ru-RU", "zh-CN"]
+
 
//get a random language
+
        // Define the Nokia Maps
var randomLanguageIndex = Math.floor(Math.random() * availableLanguages.length); var randomLanguage = availableLanguages[randomLanguageIndex];
+
        var map = new nokia.maps.map.Display(mapContainer, {
// Get and store the current map default language
+
        // initial center and zoom level of the map
var currentLanguage = appContext.get("defaultLanguage");
+
            center: [53.1, 13.1],
// Display a note to the user within the document
+
            zoomLevel: 4,
document.write("The current Default Language is " + currentLanguage);
+
            components: [
// Write line break
+
                new nokia.maps.map.component.ZoomBar(),
document.write("<br />");
+
                new nokia.maps.map.component.Behavior(),
// Set the default language of the map  
+
                new nokia.maps.map.component.TypeSelector(),
appContext.set("defaultLanguage", randomLanguage);
+
                new nokia.maps.map.component.Traffic(),
// Get the language we have just set
+
                new nokia.maps.map.component.PublicTransport(),
currentLanguage = appContext.get("defaultLanguage");
+
                new nokia.maps.map.component.Overview(),
// Write the new language
+
                new nokia.maps.map.component.ScaleBar(),
document.write("Now the Default Language is " + currentLanguage);  
+
                new nokia.maps.positioning.component.Positioning(),
// Write line break document.write("<br />");
+
                new nokia.maps.map.component.RightClick(),
</script>  
+
                new nokia.maps.search.component.RightClick(),
</body>  
+
                new nokia.maps.routing.component.RightClick()
 +
        ]
 +
    });
 +
//]]>
 +
    </script>  
 +
  </body>  
 
</html>
 
</html>
 
</code>
 
</code>

Revision as of 15:43, 6 February 2012

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

Article Metadata
Dependencies: Nokia Maps 2.1.0
Article
Created: Maveric (25 Oct 2011)
Last edited: jasfox (06 Feb 2012)
See Also

Contents

Prerequisites

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

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".

Implementation

This is a full HTML & JavaScript example. 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>
<!-- By default we add ?kml=auto&heatmap=auto to auto load KML & heatmap package remove params if package are not needed -->
<script type="text/javascript" charset="UTF-8" src="http://api.maps.nokia.com/2.1.0/jsl.js?kml=auto&amp;heatmap=auto">
</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[
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 new 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(),
new nokia.maps.map.component.RightClick(),
new nokia.maps.search.component.RightClick(),
new nokia.maps.routing.component.RightClick()
]
});
//]]>
</script>
</body>
</html>

Tested with

Mozilla FireFox 8.0 Google Chrome 14.0.835.202 m

127 page views in the last 30 days.
×