×

Discussion Board

Results 1 to 4 of 4

Hybrid View

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    29

    JavaME Nokia Maps API: how to display additional info on marker click?

    Hi,

    I need to display an additional info for a marker when it's clicked. I expected to find a way how to display a popup window (like a tooltip) with a short description on marker click, but failed.
    I use MapMarker class for my markers because I need custom icons.
    The MapMarker and MapStandardMarker classes do not have the functionality I need.

    As I understand, I need something like "Android MapView Balloons" https://github.com/jgilfelt/android-apviewballoons

    Regards,
    Alexey

  2. #2
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: JavaME Nokia Maps API: how to display additional info on marker click?

    Hi azakharo,

    So first you need to find a way to catch the click on the marker and then you need to change the marker to a tooltip.
    If a marker is not clicked, how should it look like? Can it be a standard marker (like a balloon) or not?

    Also, after the marker is clicked, what kind of information do you need in the tooltip (i.e. are you happy with a map marker with a custom icon)?

    The first part of catching the click on the marker can be done as follows (in this example I used standard markers and I just change their shape):

    Main MIDlet:
    Code:
    import javax.microedition.lcdui.Display;
    import javax.microedition.midlet.MIDlet;
    
    public class NokiaMapsMIDlet extends MIDlet
    {
    	Display display;
    	MapCanvasImpl mapcanvas;
    	
        public void startApp()
        {
        	//ApplicationContext ctx = ApplicationContext.getInstance();
            //ctx.setAppID("MyAppId");
            //ctx.setToken("MyToken");
            display = Display.getDisplay(this);
           	mapcanvas = new MapCanvasImpl(display);       	
            display.setCurrent(mapcanvas);
        }
        public void destroyApp(boolean unconditional){}
        public void pauseApp() {}
    }
    Supporting class:
    Code:
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Graphics;
    import com.nokia.maps.common.GeoBoundingBox;
    import com.nokia.maps.common.GeoCoordinate;
    import com.nokia.maps.map.MapCanvas;
    import com.nokia.maps.map.MapDisplay;
    import com.nokia.maps.map.MapShapeType;
    import com.nokia.maps.map.MapStandardMarker;
    import com.nokia.maps.map.Point;
    
    public class MapCanvasImpl extends MapCanvas
    {
    	GeoCoordinate markergeo;
    	GeoBoundingBox markerbox;
    	MapStandardMarker marker;
    	MapDisplay mapdisplay;
    	GeoCoordinate clickgeo;
    
    	public MapCanvasImpl(Display display) 
    	{
    		super(display);
    		mapdisplay=getMapDisplay();
    		markergeo=new GeoCoordinate(41.90311, 12.49576, 0.0f);
            marker = getMapFactory().createStandardMarker(markergeo, 48, null, MapShapeType.baloon);
            markerbox=marker.getBoundingBox();
            mapdisplay.addMapObject(marker);
            
    	}
    	
    	protected void pointerPressed(int x, int y)
    	{
    		super.pointerPressed(x, y);
    		clickgeo=mapdisplay.pixelToGeo(new Point(x,y));
    	
    		if(markerbox.contains(clickgeo))
    		{
    			if(marker.getShapeType()==MapShapeType.baloon)
    			{
    				marker.setShapeType(MapShapeType.star);
    				GeoCoordinate newgeo=new GeoCoordinate(41.90312, 12.49576, 0.0f);
    				marker.setCoordinate(newgeo);
    			}
    			else
    			{
    				marker.setShapeType(MapShapeType.baloon);
    				GeoCoordinate newgeo=new GeoCoordinate(41.90311, 12.49576, 0.0f);
    				marker.setCoordinate(newgeo);
    			}
    			repaint();
    		}
    	}
    
    	protected void paint(Graphics g)
    	{
    		super.paint(g);
    		markerbox=marker.getBoundingBox();
    	}
    }
    Please note that there is currently a bug in the library (version 0.5) where the repaint doesn't update the map if the marker has changed shape, while it does, if the marker has changed coordinates.

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    29

    Re: JavaME Nokia Maps API: how to display additional info on marker click?

    I've solved the problem. I use the popup dialog similar to the one implemented in "Meet Me For Dinner" sample application. All necessary info can be found http://terrencebarr.wordpress.com/20...ideo-released/.

    I met the problem with detecting a click on marker. For this I used MapDisplay.getObjectAt () method. But it looks like that method doesn't take into account the marker's anchor point. So, I had to use the following work-around for this:

    final MapObject mapObj = mapDisp.getObjectAt ( new Point (
    clickX + m_markerIconSize.getWidth (),
    clickY + m_markerIconSize.getHeight () )
    );
    if ( (mapObj != null) && (mapObj instanceof MapMarker) ) {

  4. #4
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: JavaME Nokia Maps API: how to display additional info on marker click?

    Hi azakharo and thank you for the input,

    There is a new version (1.0) of Nokia Maps API for Java ME, recently released, that supports KML, thus making it much easier to display popup windows. You might want to check the articles found on this link and this one, in order to see if the suggested implementation for displaying a tooltip on marker click has been simplified. Keep in mind that certain changes to the API in the recent version 1.0, might require that you need to do modifications in other parts of your code, as certain classes of the API have been modified, others deleted and new ones added.
    Last edited by skalogir; 2012-04-20 at 14:42.

Similar Threads

  1. Change Marker in Google Maps
    By Mobile Developer in forum Mobile Java General
    Replies: 9
    Last Post: 2011-12-08, 13:18
  2. Click on Marker of Ovi map........
    By amitsharma_ujj in forum Qt
    Replies: 5
    Last Post: 2011-09-28, 09:30
  3. Marker is not display in the Google Map of Nokia C5
    By senthil_25 in forum Nokia Asha Web Apps
    Replies: 0
    Last Post: 2011-07-02, 12:09
  4. Replies: 2
    Last Post: 2010-08-30, 12:03

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×