×
Namespaces

Variants
Actions
(Difference between revisions)

Setting the Map language in the Maps API for Java ME

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
hamishwillee (Talk | contribs)
m (Text replace - "S40" to "Series 40")
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Nokia Maps]][[Category:Code Snippet]][[Category:Java ME]][[Category:Series 40]][[Category:Symbian]][[Category:Series 40 Developer Platform 2.0]][[Category:Series 40 6th Edition FP1]][[Category:Series 40 Developer Platform 1.1]][[Category:Java Runtime 2.0.0 for Series 40]]
+
[[Category:HERE Maps]][[Category:Code Snippet]][[Category:Java ME]][[Category:Series 40]][[Category:Symbian]][[Category:Series 40 Developer Platform 2.0]][[Category:Series 40 6th Edition FP1]][[Category:Series 40 Developer Platform 1.1]][[Category:Series 40 Developer Platform 2.0]][[Category:Code Examples]]
 
{{Abstract|This article explains how to alter the''' map language'''  of a Java ME application }}  
 
{{Abstract|This article explains how to alter the''' map language'''  of a Java ME application }}  
{{ArticleMetaData
+
 
|sourcecode= [[Media:MapLanguageMIDlet.zip | Map Language MIDlet Source]]<!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
+
{{ArticleMetaData <!-- v1.2 -->
|installfile= [[Media:MapLanguageMIDletBinaries.zip | Map Language MIDlet Binaries]]<!--  Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
+
|sourcecode= [[Media:MapLanguageMIDlet.zip]]
|devices=X3-02, Asha 305
+
|installfile= [[Media:MapLanguageMIDletBinaries.zip]]
|sdk=[http://www.developer.nokia.com/Develop/Java/ Nokia SDK 1.0 for Java], [http://www.developer.nokia.com/Develop/Java/ Nokia SDK 2.0 for Java (beta)]
+
|devices= X3-02, Asha 305
|dependencies= [http://www.developer.nokia.com/Develop/Maps/Maps_API_for_Java_ME/ Maps API for Java ME] v1.1
+
|sdk= [http://www.developer.nokia.com/Develop/Java/ Nokia SDK 1.0 for Java], [http://www.developer.nokia.com/Develop/Java/ Nokia SDK 2.0 for Java (beta)]
|platform=S40, Symbian^1, Symbian^3
+
|platform= Series 40, Symbian^1, Symbian^3
|devicecompatability=All
+
|devicecompatability= All
|signing=
+
|dependencies= [http://www.developer.nokia.com/Develop/Maps/Maps_API_for_Java_ME/ Maps API for Java ME] v1.1
|capabilities=<!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
+
|signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
|keywords=Location API, Nokia Maps, MapDisplay, Application Context, Language
+
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
|id= <!-- Article Id (Knowledge base articles only) -->
+
|keywords= Location API, Nokia Maps, MapDisplay, Application Context, Language
|creationdate=20120323
+
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 
|update-by= <!-- -->
 
|update-by= <!-- -->
|update-timestamp=<!-- -->
+
|update-timestamp= <!-- -->
|author=[[User:jasfox]]
+
|creationdate= 20120323
 +
|author= [[User:jasfox]]
 
}}
 
}}
 
{{SeeAlso|
 
{{SeeAlso|
Line 22: Line 28:
 
* [[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]]
 
* [[How to create custom Map View in Java ME|How to create custom Map View]]
 
* [[How to create custom Map View in Java ME|How to create custom Map View]]
 +
* [[Localising app attributes in Java ME|Localising app attributes]]
 
}}
 
}}
 
== Introduction ==
 
== Introduction ==
Line 27: Line 34:
  
 
{{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.
<Code language=java>System.getProperty("microedition.locale");</Code>This will retrieve a 2 letter MARC Code, which can be mapped onto a 3 letter MARC code using a simple {{Icode|switch}}  statement.
+
<Code java>System.getProperty("microedition.locale");</Code>This will retrieve a two letter MARC Code, which can be mapped onto a three letter MARC code using a simple {{Icode|switch}}  statement. Alternatively a locallized three letter MARC code could be [[Localising app attributes in Java ME|read from the JAD file]]
 
  }}
 
  }}
  

Revision as of 08:53, 10 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: hamishwillee (10 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
601 page views in the last 30 days.
×