×
Namespaces

Variants
Actions
(Difference between revisions)

Adding Markers to the Map with Maps API for Java ME

From Nokia Developer Wiki
Jump to: navigation, search
trashedDev (Talk | contribs)
(TrashedDev -)
jasfox (Talk | contribs)
m (Jasfox - Link to GitHub)
 
(20 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Category:Java ME]][[Category:Nokia Maps]][[Category:Location]][[Category:Code Examples]][[Category:Series 40]][[Category:Series 40 6th Edition FP1]][[Category:Java Runtime 1.1.0 for Series 40]][[Category:Series 40 Developer Platform 2.0]][[Category:Java Runtime 2.0.0 for Series 40]]
+
[[Category:Code Examples]][[Category:Series 40]][[Category:Series 40 6th Edition FP1]][[Category:Series 40 Developer Platform 1.1]][[Category:Series 40 Developer Platform 2.0]][[Category:Series 40 Developer Platform 2.0]][[Category:HERE Maps for Java ME]][[Category:Nokia Asha Platform 1.0]][[Category:Nokia Asha]]
{{Abstract| This article explains how to add markers into the map with [http://www.developer.nokia.com/Develop/Maps/Maps_API_for_Java_ME/ Maps API for Java ME] API and also how to make them draggable.}}
+
{{Abstract| This article explains how to add markers onto the map with the [http://www.developer.nokia.com/Resources/Library/HERE_Maps_Java_ME/#!index.html HERE Maps API for Java ME] API and also how to make them draggable.}}
 
+
{{SeeAlso|
 +
*  [http://www.developer.nokia.com/Resources/Library/HERE_Maps_Java_ME/#!user-guide/maps/markers.html Markers]  (Java Developer's Library)
 +
* [[How to create a draggable marker with Maps API for Java ME| Draggable Markers]]
 +
*  [https://github.com/nokia-developer/here-maps-component-demos HERE Maps Code Examples]
 +
}}
 
{{ArticleMetaData
 
{{ArticleMetaData
 
|sourcecode= [[Media: Java_MapsMarker.zip | MapsMarker Sources]]<!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
 
|sourcecode= [[Media: Java_MapsMarker.zip | MapsMarker Sources]]<!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
 
|installfile= [[Media:MapsMarker_binaries.zip | MapsMarker Binaries]]<!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|installfile= [[Media:MapsMarker_binaries.zip | MapsMarker Binaries]]<!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|devices= C3-01, Nokia Asha 306<!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
+
|devices= C3-01, Nokia Asha 306, X3-02, Asha 311, Asha 501
|sdk= [http://www.developer.nokia.com/Develop/Java/ Nokia SDK 1.1 for Java], [http://www.developer.nokia.com/Develop/Java/ Nokia SDK 2.0 for Java (beta)] <!-- 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.0 for Java], [http://www.developer.nokia.com/Develop/Java/ Nokia SDK 2.0 for Java], [http://www.developer.nokia.com/Develop/asha/java/ Nokia Asha SDK 1.0]
|platform= S40
+
|platform= Asha, Series 40, Symbian^1, Symbian^3
 
|devicecompatability= All <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 
|devicecompatability= All <!-- Compatible devices e.g.: All* (must have internal GPS) -->
|dependencies= [http://www.developer.nokia.com/Develop/Maps/Maps_API_for_Java_ME/ Maps API 1.1 for Java ME]
+
|dependencies= HERE Maps API for Java ME v1.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= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
+
|keywords= HERE Maps, Java ME, markers
 
|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 24: Line 28:
 
|creationdate=20120227
 
|creationdate=20120227
 
|author=[[User:symbianyucca]]
 
|author=[[User:symbianyucca]]
}}
 
{{SeeAlso|
 
*  [http://www.developer.nokia.com/Develop/Maps/Maps_API_for_Java_ME/ Map API for Java ME]
 
* [http://www.developer.nokia.com/Develop/Maps/Maps_API_for_Java_ME/Code_examples/#standard Adding a Standard Marker]
 
* [http://www.developer.nokia.com/Develop/Maps/Maps_API_for_Java_ME/Code_examples/#custom Adding a Custom Marker]
 
 
}}
 
}}
 +
  
 
== Introduction ==
 
== Introduction ==
  
 
[[File:MapsMarker.png]]
 
[[File:MapsMarker.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 API also includes functionality on adding markers into the map.
+
 
 +
The [http://www.developer.nokia.com/Resources/Library/HERE_Maps_Java_ME/#!index.html HERE Maps API for Java ME] makes it possible to easily embed HERE Maps service into Java ME applications. The API also includes the functionality to add markers to the map.
  
 
== Constructing and adding markers ==
 
== Constructing and adding markers ==
 
Markers are added to the Map by adding them into the instance of MapDisplay object, which can be retrieved from current MapCanvas object.
 
Markers are added to the Map by adding them into the instance of MapDisplay object, which can be retrieved from current MapCanvas object.
Note that you should never try constructing the marker directly, instead it should be constructed utilizing functions provided by the MapFactory. An instance of the MapFactory can be retrieved with the MapCanvas object, and then createMapMarker method can be used for constructing marker:
+
Note that you should never try constructing the marker directly, instead it should be constructed utilizing functions provided by the MapFactory. An instance of the MapFactory can be retrieved with the MapCanvas object, and then the createMapMarker method can be used to construct the marker:
 
<code java>
 
<code java>
 
MapMarker marker = mapFactory.getMapFactory().createMapMarker(position, Image.createImage("/nokiaicon.png"));
 
MapMarker marker = mapFactory.getMapFactory().createMapMarker(position, Image.createImage("/nokiaicon.png"));
Line 44: Line 45:
 
</code>
 
</code>
  
You can use custom images with createMapMarker  method as shown above, or if you want, you could also use following predefined shapes:
+
You can use custom images with createMapMarker  method as shown above, or if you want, you can also use the following predefined shapes:
 
* BALLOON  
 
* BALLOON  
 
* HEXAGON  
 
* HEXAGON  
Line 60: Line 61:
  
 
=== Implementing Draggable markers ===
 
=== Implementing Draggable markers ===
As shown in [http://www.developer.nokia.com/Community/Wiki/Handling_map_events_with_Java_ME_Location_API Handling map events with Maps API for Java ME] article, if you want to catch map pointer events, you need to implement  a custom {{Icode|MapComponent}} with an {{Icode|EventListener}}. Thus with draggable markers you need to implement these components as well, and with this example all logic for dragging is also implemented inside the {{Icode|EventListener}} component.
+
As shown in [http://www.developer.nokia.com/Community/Wiki/Handling_map_events_with_Java_ME_Location_API Handling map events with Maps API for Java ME] article, if you want to catch map pointer events, you need to implement  a custom {{Icode|MapComponent}} with an {{Icode|EventListener}}. Thus with draggable markers you need to implement these components as well, and in this example all logic for dragging is also implemented inside the {{Icode|EventListener}} component.
First thing to do with the pointer events is then to catch the event where the {{Icode|Marker}} is pressed before the dragging is started. This naturally is handled inside the {{Icode|pointerPressed()}} method:
+
The first thing to do with the pointer events is then to catch the event where the {{Icode|Marker}} is pressed before the dragging is started. This naturally is handled inside the {{Icode|pointerPressed()}} method:
 
<code java>
 
<code java>
 
public boolean pointerPressed(int x, int y) {
 
public boolean pointerPressed(int x, int y) {
Line 129: Line 130:
 
== 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/Resources/Library/HERE_Maps_Java_ME/#!index.html HERE Maps API for Java ME ] offers rich functionalities that makes it possible to integrate all the HERE Maps features in a Java ME application, with just a few lines of code.

Latest revision as of 12:11, 20 September 2013

This article explains how to add markers onto the map with the HERE Maps API for Java ME API and also how to make them draggable.

See Also
Article Metadata
Code Example
Installation file: MapsMarker Binaries
Tested with
Devices(s): C3-01, Nokia Asha 306, X3-02, Asha 311, Asha 501
Compatibility
Device(s): All
Dependencies: HERE Maps API for Java ME v1.3
Article
Keywords: HERE Maps, Java ME, markers
Created: symbianyucca (27 Feb 2012)
Last edited: jasfox (20 Sep 2013)


Contents

[edit] Introduction

MapsMarker.png

The HERE Maps API for Java ME makes it possible to easily embed HERE Maps service into Java ME applications. The API also includes the functionality to add markers to the map.

[edit] Constructing and adding markers

Markers are added to the Map by adding them into the instance of MapDisplay object, which can be retrieved from current MapCanvas object. Note that you should never try constructing the marker directly, instead it should be constructed utilizing functions provided by the MapFactory. An instance of the MapFactory can be retrieved with the MapCanvas object, and then the createMapMarker method can be used to construct the marker:

MapMarker marker = mapFactory.getMapFactory().createMapMarker(position, Image.createImage("/nokiaicon.png"));
mapCanvas.getMapDisplay().addMapObject(marker);

You can use custom images with createMapMarker method as shown above, or if you want, you can also use the following predefined shapes:

  • BALLOON
  • HEXAGON
  • OCTAGON
  • PENTAGON
  • RECTANGLE
  • SQUARE
  • STAR
  • TRIANGLE

When using the shapes, you can also define the size in pixels (as second argument) as well as the text (as third argument) to be used inside the marker as illustrated below:

MapMarker marker = mapFactory.createStandardMarker(new GeoCoordinate(latitude, longitude, altitude),40, "3",MapStandardMarker.SQUARE);

[edit] Implementing Draggable markers

As shown in Handling map events with Maps API for Java ME article, if you want to catch map pointer events, you need to implement a custom MapComponent with an EventListener. Thus with draggable markers you need to implement these components as well, and in this example all logic for dragging is also implemented inside the EventListener component. The first thing to do with the pointer events is then to catch the event where the Marker is pressed before the dragging is started. This naturally is handled inside the pointerPressed() method:

public boolean pointerPressed(int x, int y) {
if(mapDisplay != null){
Point nowPoint = new Point(x,y);
MapObject selObj = mapDisplay.getObjectAt(nowPoint);
if (selObj != null && selObj instanceof MapStandardMarker) {
marker = (MapStandardMarker)selObj;
clicking = true;
movingMarker = false;
return true;
}else {
return false;
}
} else {
return false;
}
}

Basically with the code the getObjectAt() method is used for determining whether there is a Marker under the point pressed, and if there is, then dragging is started. Then the next step is to actually drag the marked when user moves the pointer in the map.

public boolean pointerDragged(int x, int y) {
if(marker != null){
clicking = false;
movingMarker = true;
marker.setCoordinate(mapDisplay.pixelToGeo(new Point(x, y)));
mapCanvas.repaint();
return true;
}else{
movingMarker = clicking = false;
return false;
}
}

Note that if there is no Marker selected in the pointerPressed() method, then this function need to return false, otherwise the normal panning with the map would also be disabled. And once the user stops the dragging and lifts the finger from the map, then the pointerReleased() method is called. In this method we need to finalize the dragging, also with this example there is separate handling for clicking the Marker:

public boolean pointerReleased(int x, int y) {
boolean retVal = false;
if(marker != null){
if(clicking){
mapDisplay.setCenter(marker.getCoordinate());
mapCanvas.repaint();
retVal = true;
}else if(movingMarker){
marker.setCoordinate(mapDisplay.pixelToGeo(new Point(x, y)));
mapDisplay.setCenter(marker.getCoordinate());
mapCanvas.repaint();
retVal = true;
}
 
}
 
marker = null;
clicking = movingMarker = false;
return retVal;
}

[edit] Resources

Full source code of the MapRevGeoCoding is available here: File:Java MapsMarker.zip

Installation files are available here: File:MapsMarker binaries.zip

[edit] Summary

The HERE Maps API for Java ME offers rich functionalities that makes it possible to integrate all the HERE Maps features in a Java ME application, with just a few lines of code.

This page was last modified on 20 September 2013, at 12:11.
296 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.

×