Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

(Difference between revisions)

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

From Wiki
Jump to: navigation, search
jasfox (Talk | contribs)
m (Jasfox - - Implementation)
jasfox (Talk | contribs)
m (Jasfox - Update links)
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Nokia Maps]][[Category:Code Snippet]][[Category:JavaScript]]
+
[[Category:HERE Maps]][[Category:JavaScript]][[Category:Code Examples]]
 
{{Abstract|This articles shows how to get and set the default language in application context.  }}
 
{{Abstract|This articles shows how to get and set the default language in application context.  }}
 
{{ArticleMetaData
 
{{ArticleMetaData
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
+
|sourcecode= [[https://github.com/heremaps/examples/blob/master/maps_api_for_javascript/advanced-examples/map-language.html map-language.html]]
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|devices= Internet Explorer, Google Chrome, Firefox, Opera
 
|devices= Internet Explorer, Google Chrome, Firefox, Opera
Line 8: Line 8:
 
|platform= Web browsers
 
|platform= Web browsers
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
|dependencies=Nokia Maps 2.2.3
+
|dependencies=HERE Maps 2.5.3
 
|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. -->
|keywords= Nokia Maps, JavaScript, default language
+
|keywords= HERE Maps, JavaScript, default language
 
|id= <!-- Article Id (Knowledge base articles only) -->
 
|id= <!-- Article Id (Knowledge base articles only) -->
 
|language=<!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
|language=<!-- Language category code for non-English topics - e.g. Lang-Chinese -->
Line 22: Line 22:
 
}}
 
}}
 
{{SeeAlso|
 
{{SeeAlso|
* [http://developer.here.net/javascript_api Nokia Maps API]
+
* [http://developer.here.net/javascript_api HERE Maps API]
 
*  [http://www.developer.nokia.com/Community/Wiki/Nokia_Maps_API_-_Setting_the_language Setting the Language]
 
*  [http://www.developer.nokia.com/Community/Wiki/Nokia_Maps_API_-_Setting_the_language Setting the Language]
 
* [http://developer.here.net/apiexplorer/examples/api-for-js/map/map-change-language.html Changing the language of the map]  }}
 
* [http://developer.here.net/apiexplorer/examples/api-for-js/map/map-change-language.html Changing the language of the map]  }}
Line 28: Line 28:
 
==Prerequisites==   
 
==Prerequisites==   
  
Nokia Maps API supported web browser (basically any modern web browser)
+
HERE Maps API supported web browser (basically any modern web browser)
  
 
==Important note about maps credentials==
 
==Important note about maps credentials==
Line 37: Line 37:
 
==Implementation==   
 
==Implementation==   
  
This is a full HTML & JavaScript exampleAdd in your own [[How to Obtain Your Own Nokia appID and Token| AppId and Token]] and feel free to modify and use for your own purposes.
+
The following code displays and alters the map language. Note that the language must be set prior to instantiating the map.  
  
 
<code javascript>
 
<code javascript>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
function setMapLanguage(){
<html xmlns="http://www.w3.org/1999/xhtml">
+
var availableLanguages = ["en-US", "en-GB", "de-DE", "es-ES",
<head>
+
"fr-FR", "it-IT", "ru-RU", "zh-CN"] ,
<meta http-equiv="content-type" content=
+
randomLanguageIndex = Math.floor(Math.random() * availableLanguages.length),
"text/html; charset=us-ascii" />
+
randomLanguage = availableLanguages[randomLanguageIndex];
<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.3/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">     
+
$("#initialLangauge").text("The Initial Default Language is " +  
var appContext = nokia.maps.util.ApplicationContext;
+
nokia.Settings.defaultLanguage);  
// 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
+
nokia.Settings.set("defaultLanguage", randomLanguage);
var mapContainer = document.getElementById("mapContainer");
+
$("#currentLanguage").text("Now the Default Language is " +
 
+
nokia.Settings.defaultLanguage);  
// Define the Nokia Maps
+
var map = new nokia.maps.map.Display(mapContainer, {
+
        // initial center and zoom level of the map
+
map = new nokia.maps.map.Display(document.getElementById('mapContainer'), {
        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()
                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>
+
 
</code>
 
</code>
 +
 +
The following fully working example can be found at:
 +
 +
http://rawgithub.com/heremaps/examples/master/maps_api_for_javascript/advanced-examples/map-language.html

Latest revision as of 11:57, 28 November 2013

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

Article Metadata
Code Example
Source file: [map-language.html]
Tested with
Devices(s): Internet Explorer, Google Chrome, Firefox, Opera
Compatibility
Platform(s): Web browsers
Dependencies: HERE Maps 2.5.3
Article
Keywords: HERE Maps, JavaScript, default language
Created: Maveric (25 Oct 2011)
Last edited: jasfox (28 Nov 2013)

[edit] Prerequisites

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

[edit] Important note about maps credentials

Nokia provides several services options within the Maps API offering. The service is free to use, but you must obtain and use authentication and authorization credentials to use the services. Please read the Terms and Conditions and check the Pricing Plans page to decide which business model best fits your needs. Authentication requires unique Maps API credentials, namely an AppId and a token. You can get these credentials free for free following the instructions here

[edit] Implementation

The following code displays and alters the map language. Note that the language must be set prior to instantiating the map.

function setMapLanguage(){
var availableLanguages = ["en-US", "en-GB", "de-DE", "es-ES",
"fr-FR", "it-IT", "ru-RU", "zh-CN"] ,
randomLanguageIndex = Math.floor(Math.random() * availableLanguages.length),
randomLanguage = availableLanguages[randomLanguageIndex];
 
$("#initialLangauge").text("The Initial Default Language is " +
nokia.Settings.defaultLanguage);
 
nokia.Settings.set("defaultLanguage", randomLanguage);
$("#currentLanguage").text("Now the Default Language is " +
nokia.Settings.defaultLanguage);
 
 
map = new nokia.maps.map.Display(document.getElementById('mapContainer'), {
center: [53.1, 13.1],
zoomLevel: 4,
components: [
new nokia.maps.map.component.ZoomBar(),
new nokia.maps.map.component.Behavior()
]
});
}

The following fully working example can be found at:

http://rawgithub.com/heremaps/examples/master/maps_api_for_javascript/advanced-examples/map-language.html

This page was last modified on 28 November 2013, at 11:57.
212 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×