×
Namespaces

Variants
Actions
(Difference between revisions)

Content Handling with Maps API for Java ME

From Nokia Developer Wiki
Jump to: navigation, search
avnee.nathani (Talk | contribs)
(Avnee.nathani - adding metadata, fix link)
hamishwillee (Talk | contribs)
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
[[Category:Java ME]][[Category:Location]][[Category:Nokia Maps]][[Category:Code Examples]]
+
[[Category:Java ME]][[Category:Location]][[Category:Nokia Maps]][[Category:Code Examples]][[Category:Series 40]][[Category:Series 40 6th Edition FP1]][[Category:Series 40 Developer Platform 1.1]]
{{Abstract| This article explains how to add different types of content to the Map when using [http://www.developer.nokia.com/Develop/Maps/Maps_API_for_Java_ME/ Maps API for Java ME] API. Also removing and other functionalities included with content are also illustrated in this article.}}
+
{{Abstract| This article explains how to add different types of content to the Map when using [http://www.developer.nokia.com/Develop/Maps/Maps_API_for_Java_ME/ Maps API for Java ME] API. Removing content and other content functionality is also dealt with in this article.}}
  
 
{{ArticleMetaData
 
{{ArticleMetaData
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
+
|sourcecode= [[Media:Java_MapContent.zip | ContentHandling Sources]] <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
+
|installfile= [[Media:ContentHandling_binaries.zip | ContentHandling Binaries]] <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
+
|devices= C3-01<!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
+
|sdk= [http://www.developer.nokia.com/Develop/Java/ Nokia SDK 1.1 for Java]<!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|platform= Java ME
+
|platform= S40
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
|dependencies= Maps API for Java ME
+
|dependencies= [http://www.developer.nokia.com/Develop/Maps/Maps_API_for_Java_ME/ Maps API 1.1 for Java]
 
|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= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
+
|keywords= Nokia Maps, Java ME, content, content handling
 
|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 31: Line 31:
 
[[File: MapContent.png]]
 
[[File: MapContent.png]]
  
The [http://www.developer.nokia.com/Develop/Maps/Maps_API_for_Java_ME/ Maps API for Java ME] allows to easily embed Nokia Maps service into Java ME applications.  
+
The [http://www.developer.nokia.com/Develop/Maps/Maps_API_for_Java_ME/ Maps API for Java ME] makes it possible to easily embed the Nokia Maps service into Java ME applications.  
  
Markers are discussed already in [http://www.developer.nokia.com/Community/Wiki/Adding_Markers_to_the_Map_with_Maps_API_for_Java_ME Adding Markers to the Map with Maps API for Java ME] article, thus this article will concentrate on other types of content that can be added to the map.
+
{{Icode|MapMarkers}} have already been discussed  in the [http://www.developer.nokia.com/Community/Wiki/Adding_Markers_to_the_Map_with_Maps_API_for_Java_ME Adding Markers to the Map with Maps API for Java ME] article, thus this article will concentrate on other types of content that may be added to the map.
  
 
== Adding content to the map ==
 
== Adding content to the map ==
Addition to the Markers following content types have class definition included with the Java ME Maps API:
+
In addition to {{Icode|MapMarkers}} the following content types have class definition included with the Java ME Maps API:
* Polygon,
+
* {{Icode|Polygon}},
* Polyline,
+
* {{Icode|Polyline}},
* Circle, and
+
* {{Icode|Circle}}, and
* Rectangle
+
* {{Icode|Rectangle}}
  
Polylines can be constructed by using MapFactory, the constructor takes only one argument, which is array of points for the polyline. after construction you can use the methods provide by the MapPolyline class to modify it, for example you can change the color of the line with setColor method.
+
{{Icode|Polylines}} can be constructed by using the {{Icode|MapFactory}}, the constructor takes only one argument, which is an array of points for the {{Icode|Polyline}}. after construction you can use the methods provide by the {{Icode|MapPolyline}} class to modify it, for example you can change the color of the line with {{Icode|setColor()}} method.
 
<code java>
 
<code java>
 
GeoCoordinate[] polylinCoord = new GeoCoordinate[4];
 
GeoCoordinate[] polylinCoord = new GeoCoordinate[4];
Line 56: Line 56:
 
</code>
 
</code>
  
Similarly as Polylines, polygons are constructed with MapFactory, and the constructor also takes the array of points:
+
In a similar manner to {{Icode|Polylines}}, {{Icode|Polygons}} are constructed via the  {{Icode|MapFactory}}, and the constructor also takes the array of points:
 
<code java>
 
<code java>
 
GeoCoordinate[] polygonCoord = new GeoCoordinate[3];
 
GeoCoordinate[] polygonCoord = new GeoCoordinate[3];
Line 68: Line 68:
 
mapCanvas.getMapDisplay().addMapObject(polygon);
 
mapCanvas.getMapDisplay().addMapObject(polygon);
 
</code>
 
</code>
Circle and rectangle are basically special polygons helper classes. For circle the constructor takes two arguments, which are radius and center. And for the rectangle the only argument taken is bounding box for the rectangle, which is basically area defined by two points, left top point and the bottom right point.
+
The {{Icode|Circle}} and {{Icode|rectangle}} are basically special polygons helper classes. For the {{Icode|Circle}} the constructor takes two arguments, which are the {{Icode|radius}} and {{Icode|center}}. And for the {{Icode|Rectangle}} the only argument taken is bounding box for the rectangle, which is basically area defined by two points, left top point and the bottom right point.
 
<code java>
 
<code java>
 
MapCircle myCircle = mapCanvas.getMapFactory().createMapCircle(5000.0,new GeoCoordinate(60.30, 24.70,0));
 
MapCircle myCircle = mapCanvas.getMapFactory().createMapCircle(5000.0,new GeoCoordinate(60.30, 24.70,0));
 
+
// ...
 
GeoBoundingBox rectnaglebox = new GeoBoundingBox(new GeoCoordinate(60.35, 24.60,0), new GeoCoordinate(60.25, 24.80,0));
 
GeoBoundingBox rectnaglebox = new GeoBoundingBox(new GeoCoordinate(60.35, 24.60,0), new GeoCoordinate(60.25, 24.80,0));
 
MapRectangle rectnagle = mapCanvas.getMapFactory().createMapRectangle(rectnaglebox);
 
MapRectangle rectnagle = mapCanvas.getMapFactory().createMapRectangle(rectnaglebox);
 
</code>
 
</code>
 +
 
== Z-ordering content ==
 
== Z-ordering content ==
The Z-ordering content is handled simply by using the setzIndex method for each content that needs to be ordered. Giving smaller value in setzIndex will make the content to be drawn under the content that has higher values.
+
The Z-ordering content is handled simply by using the {{Icode|setzIndex()}} method for each content that needs to be ordered. Giving a lower value in {{Icode|setzIndex()}}  will make the content to be drawn under the content that has higher values.
For example if you want myCircle to be drawn on top of the rectangle, you can do it with following code:
+
For example if you want {{Icode|myCircle}} to be drawn on top of the {{Icode|rectangle}}, you can do it with following code:
 
<code java>
 
<code java>
 
int markerZ = 1;
 
int markerZ = 1;
 
int polyZ = 0;
 
int polyZ = 0;
 
myCircle.setzIndex(markerZ);
 
myCircle.setzIndex(markerZ);
rectnagle.setzIndex(polyZ);
+
rectangle.setzIndex(polyZ);
 
</code>
 
</code>
 
== Hiding content without deleting them ==
 
== Hiding content without deleting them ==
Each content item can be hidden by calling setVisible method with Boolean argument set to false value:
+
Each content item can be hidden by calling the {{Icode|setVisible()}}  method with a {{Icode|Boolean}} argument set to {{Icode|false}} :
 
<code java>
 
<code java>
 
boolean vissible = !rectnagle.isVisible();
 
boolean vissible = !rectnagle.isVisible();
Line 91: Line 92:
 
</code>
 
</code>
 
== Removing content ==
 
== Removing content ==
Each content added to the Map display with addMapObject method can be also removed by using removeMapObject method.
+
Each content added to the Map display with the {{Icode|addMapObject()}} method can be also removed by using the  {{Icode|removeMapObject()}} method.
 
<code java>
 
<code java>
 
mapCanvas.getMapDisplay().addMapObject( myCircle );
 
mapCanvas.getMapDisplay().addMapObject( myCircle );
 
</code>
 
</code>
Thus if for example myCircle object is added with the code above, it can be later on removed from the Map by using the code shown below.
+
Thus, if for example, {{Icode|myCircle}}  is added with the code above, it can be later on removed from the Map by using the code shown below.
 
<code java>
 
<code java>
 
mapCanvas.getMapDisplay().removeMapObject(myCircle);
 
mapCanvas.getMapDisplay().removeMapObject(myCircle);
Line 102: Line 103:
 
== Resources ==
 
== Resources ==
  
Full source code illustrating usage for map content types discussed in this article is available here: [[File: Java_MapContent.zip]]
+
Full source code illustrating usage for map content types discussed in this article is available at: [[File: Java_MapContent.zip]]
  
 
== Summary ==
 
== Summary ==
  
The [https://projects.developer.nokia.com/LBSPJME/wiki Java ME Location API] offers rich functionalities that allows to integrate all the main Ovi Maps features in a Java ME application, with just a few lines of code.
+
The [http://www.developer.nokia.com/Develop/Maps/Maps_API_for_Java_ME/ Maps API for Java ME] offers rich functionality which facilitates the integration of all the main Nokia Maps features into a Java ME application, with just a few lines of code.

Revision as of 05:26, 7 August 2012

This article explains how to add different types of content to the Map when using Maps API for Java ME API. Removing content and other content functionality is also dealt with in this article.

Article Metadata
Code Example
Installation file: ContentHandling Binaries
Tested with
Devices(s): C3-01
Compatibility
Dependencies: Maps API 1.1 for Java
Article
Keywords: Nokia Maps, Java ME, content, content handling
Created: symbianyucca (27 Feb 2012)
Last edited: hamishwillee (07 Aug 2012)


Contents

Introduction

MapContent.png

The Maps API for Java ME makes it possible to easily embed the Nokia Maps service into Java ME applications.

MapMarkers have already been discussed in the Adding Markers to the Map with Maps API for Java ME article, thus this article will concentrate on other types of content that may be added to the map.

Adding content to the map

In addition to MapMarkers the following content types have class definition included with the Java ME Maps API:

  • Polygon,
  • Polyline,
  • Circle, and
  • Rectangle

Polylines can be constructed by using the MapFactory, the constructor takes only one argument, which is an array of points for the Polyline. after construction you can use the methods provide by the MapPolyline class to modify it, for example you can change the color of the line with setColor() method.

GeoCoordinate[] polylinCoord = new GeoCoordinate[4];
polylinCoord[0] = new GeoCoordinate(60.27, 24.81, 0);
polylinCoord[1] = new GeoCoordinate(60.35, 24.70, 0);
polylinCoord[2] = new GeoCoordinate(60.19, 24.57, 0);
polylinCoord[3] = new GeoCoordinate(60.27, 24.81, 0);
 
MapPolyline polyline = mapCanvas.getMapFactory().createMapPolyline(polylinCoord);
polyline.setColor(0xFF43A5FF);
 
mapCanvas.getMapDisplay().addMapObject(polyline)

In a similar manner to Polylines, Polygons are constructed via the MapFactory, and the constructor also takes the array of points:

GeoCoordinate[] polygonCoord = new GeoCoordinate[3];
polygonCoord[0] = new GeoCoordinate(60.22, 24.81, 0);
polygonCoord[1] = new GeoCoordinate(60.30, 24.70, 0);
polygonCoord[2] = new GeoCoordinate(60.14, 24.57, 0);
 
MapPolygon polygon = mapCanvas.getMapFactory().createMapPolygon(polygonCoord);
polygon.setColor(0xAA43A51B);
 
mapCanvas.getMapDisplay().addMapObject(polygon);

The Circle and rectangle are basically special polygons helper classes. For the Circle the constructor takes two arguments, which are the radius and center. And for the Rectangle the only argument taken is bounding box for the rectangle, which is basically area defined by two points, left top point and the bottom right point.

MapCircle myCircle = mapCanvas.getMapFactory().createMapCircle(5000.0,new GeoCoordinate(60.30, 24.70,0));
// ...
GeoBoundingBox rectnaglebox = new GeoBoundingBox(new GeoCoordinate(60.35, 24.60,0), new GeoCoordinate(60.25, 24.80,0));
MapRectangle rectnagle = mapCanvas.getMapFactory().createMapRectangle(rectnaglebox);

Z-ordering content

The Z-ordering content is handled simply by using the setzIndex() method for each content that needs to be ordered. Giving a lower value in setzIndex() will make the content to be drawn under the content that has higher values. For example if you want myCircle to be drawn on top of the rectangle, you can do it with following code:

int markerZ = 1;
int polyZ = 0;
myCircle.setzIndex(markerZ);
rectangle.setzIndex(polyZ);

Hiding content without deleting them

Each content item can be hidden by calling the setVisible() method with a Boolean argument set to false :

boolean vissible = !rectnagle.isVisible();
rectnagle.setVisible(vissible);

Removing content

Each content added to the Map display with the addMapObject() method can be also removed by using the removeMapObject() method.

mapCanvas.getMapDisplay().addMapObject( myCircle );

Thus, if for example, myCircle is added with the code above, it can be later on removed from the Map by using the code shown below.

mapCanvas.getMapDisplay().removeMapObject(myCircle);

Resources

Full source code illustrating usage for map content types discussed in this article is available at: File:Java MapContent.zip

Summary

The Maps API for Java ME offers rich functionality which facilitates the integration of all the main Nokia Maps features into a Java ME application, with just a few lines of code.

177 page views in the last 30 days.
×