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)

Setting the Map language in the Maps API for Java ME

From Wiki
Jump to: navigation, search
jasfox (Talk | contribs)
m (Jasfox -)
jasfox (Talk | contribs)
m (Jasfox - links)
Line 25: Line 25:
 
}}
 
}}
 
{{SeeAlso|
 
{{SeeAlso|
*  [http://developer.here.com/java HERE Maps API for Java ME]
+
*  [http://www.developer.nokia.com/Resources/Library/HERE_Maps_Java_ME/#!user-guide/maps/multi-language-support.html Language support] (Java Developer's Library)
 
*  [https://projects.developer.nokia.com/mapcomponentdemos HERE Maps Code Examples]
 
*  [https://projects.developer.nokia.com/mapcomponentdemos HERE Maps Code Examples]
 
* [[Implementing a custom MapUrlProvider overlay with Maps API for Java ME|Implementing a custom MapUrlProvider overlay]]
 
* [[Implementing a custom MapUrlProvider overlay with Maps API for Java ME|Implementing a custom MapUrlProvider overlay]]
Line 32: Line 32:
 
}}
 
}}
 
== Introduction ==
 
== Introduction ==
By default all the maps in the [http://www.developer.nokia.com/Develop/Maps/Maps_API_for_Java_ME/ Map API for Java ME] will display in '''English'''. The API is however able to support a variety of other languages. The language used to display labels on the map is set in the ''ApplicationContext'', and this should be done prior to displaying the map itself. The {{Icode|setDefaultLanguage()}} method takes a three letter [http://www.loc.gov/marc/languages/language_code.html MARC Code]. If an unsupported language is requested, the map will display in English by default.
+
By default all the maps in the [http://www.developer.nokia.com/Resources/Library/HERE_Maps_Java_ME/#!index.html Map API for Java ME] will display in '''English'''. The API is however able to support a variety of other languages. The language used to display labels on the map is set in the ''ApplicationContext'', and this should be done prior to displaying the map itself. The {{Icode|setDefaultLanguage()}} method takes a three letter [http://www.loc.gov/marc/languages/language_code.html MARC Code]. If an unsupported language is requested, the map will display in English by default.
  
 
{{Tip|  It is possible to obtain the default language of the '''phone''' by requesting the {{Icode|"microedition.locale"}} system property.
 
{{Tip|  It is possible to obtain the default language of the '''phone''' by requesting the {{Icode|"microedition.locale"}} system property.

Revision as of 09:03, 23 May 2013

This article explains how to alter the map language of a Java ME application

Article Metadata
Code ExampleTested with
Devices(s): X3-02, Asha 305
Compatibility
Device(s): All
Dependencies: Maps API for Java ME v1.1
Article
Keywords: Location API, Nokia Maps, MapDisplay, Application Context, Language
Created: jasfox (23 Mar 2012)
Last edited: jasfox (23 May 2013)

Introduction

By default all the maps in the Map API for Java ME will display in English. The API is however able to support a variety of other languages. The language used to display labels on the map is set in the ApplicationContext, and this should be done prior to displaying the map itself. The setDefaultLanguage() method takes a three letter MARC Code. If an unsupported language is requested, the map will display in English by default.

Tip.pngTip: It is possible to obtain the default language of the phone by requesting the "microedition.locale" system property.

System.getProperty("microedition.locale");
This will retrieve a two letter MARC Code, which can be mapped onto a three letter MARC code using a simple switch statement. Alternatively a locallized three letter MARC code could be read from the JAD file

Examples of usable MARC codes include:

  • ARA Arabic
  • CHI Chinese
  • GER German
  • ENG English
  • FRE French
  • ITA Italian
  • RUS Russian
  • SPA Spanish

Implementation

This is a simple example of a minimal map which will display in one of eight random languages.

public class MapLanguageMIDlet extends MIDlet {
protected void startApp() throws MIDletStateChangeException {
 
// Please initialise the appId and token first
ApplicationContext ctx = ApplicationContext.getInstance();
 
ctx.setAppID("MyAppId");
ctx.setToken("MyToken");
 
Display display = Display.getDisplay(this);
MapLanguageDemo minimalMap = new MapLanguageDemo(display, this);
display.setCurrent(minimalMap);
}
protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {}
protected void pauseApp() {}
}


public class MapLanguageDemo extends MapCanvas implements CommandListener {
 
private final Command EXIT = new Command("Exit", Command.EXIT, 1);
private final static String[] MARC_CODES = {"ARA", "CHI", "GER", "ENG",
"FRE", "ITA", "RUS", "SPA"
};
private final static String[] LANGUAGES = {"Arabic", "Chinese", "German", "English",
"French", "Italian", "Russian", "Spanish"
};
protected MIDlet midlet;
 
public MapLanguageDemo(Display display, MIDlet midlet) {
super(display);
this.midlet = midlet;
init();
}
 
private void init() {
addCommand(EXIT);
 
Random r = new Random();
int i = r.nextInt(LANGUAGES.length);
ApplicationContext.getInstance().setDefaultLanguage(MARC_CODES[i]);
setTitle(LANGUAGES[i]);
setCommandListener(this);
// Set map over Europe.
map.setState(
new MapDisplayState(new GeoCoordinate(53.1, 13.1, 0), 4));
}
public void commandAction(final Command c, Displayable d) {
if (c == EXIT) {
midlet.notifyDestroyed();
}
}
public void onMapUpdateError(String description, Throwable detail, boolean critical) {
Alert alertView = new Alert("Map error: ", detail.getMessage(), null, AlertType.ERROR);
display.setCurrent(alertView);
}
public void onMapContentComplete() {
}
}

Example Output

Chinese Russian Arabic
Chinese.png Russian.png Arabic.png
245 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.

×