Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
UKSpike
Posts: 25
Registered: ‎04-07-2011
My Device: All
My Carrier: Any
Accepted Solution

Refreshing Blackberry maps

[ Edited ]

 

 

Hi 
(Apologies for last blank post- my browser refused to let me add text!)
I have written an application that plots a location on a Blackberry map. I want this to be updated every 2 minutes with the location data I have supplied.
Supplying the data is not an issue, but refreshing the map is.
I have the plotting of the map datta in an endless loop, but can't get it to refresh the screen.
A snippet of my code is as follows:
UiApplication.getUiApplication().invokeLater(new Runnable() 
{
      public void run() 
      {
            map = MapFactory.getInstance().generateRichMapField();
            add(map);
                                        
                                        
            MapDataModel data = map.getModel();   
            MapLocation loc1 = new MapLocation( currentlat,currentlong,     stroredDateSting, null);
                  
            int locId = data.add( (Mappable) loc1, "CurrentLocation");
            data.tag( locId, "Location");
            data.setVisible( "Location" );
                        
            map.getMapField().update( true );
      }
});
Thread.sleep(120000);
This is all in a method that is called from the method that implements the new thread.
Many thanks in advance!

 

Please use plain text.
Developer
sheeluwiki
Posts: 254
Registered: ‎03-15-2011
My Device: simulator
My Carrier: simulator

Re: Refreshing Blackberry maps

Here is a sample code which I have written some days back..

 

I have used RealTimeCloclListener which is used to update the location every minute..

 

public class MappingFieldSelfTrial extends UiApplication implements RealtimeClockListener{

        /**
         * Pushes the main screen onto the display stack
         */
	private double DEFAULT_LAT = 45.504512;
	private double DEFAULT_LONG = -73.557029;
	private RichMapField map = MapFactory.getInstance().generateRichMapField();
	private MapDataModel Mapdata = map.getModel();
	private MapLocation julieHome = new MapLocation( DEFAULT_LAT, DEFAULT_LONG, "Julie - Home new", "Home" );
        public MappingFieldSelfTrial() {
                pushScreen(new RichMapScreenTest(DEFAULT_LAT,DEFAULT_LONG));
                this.addRealtimeClockListener(this);
        }

        /**
         * Main Entry point for the application
         */
        public static void main(String[] args) {
                MappingFieldSelfTrial myClass = new MappingFieldSelfTrial();
                myClass.enterEventDispatcher();

        }

		public void clockUpdated() {
			
			DEFAULT_LAT = DEFAULT_LAT+ 1; // new location latitude
			DEFAULT_LONG = DEFAULT_LONG+1; // new location longitude
			UiApplication.getUiApplication().invokeLater(new Runnable() 
			{
			    public void run() {
			       Dialog.alert("Timer alert"+DEFAULT_LAT);
			    }
			});
			Mapdata.removeAll();
			setLocation(DEFAULT_LAT,DEFAULT_LONG);
		}
		
		private void setLocation(double DEFAULT_LAT, double DEFAULT_LONG ){
	        julieHome.setLat(DEFAULT_LAT);
	        julieHome.setLon(DEFAULT_LONG);
	        Mapdata.add((Mappable) julieHome );
	        map.getMapField().update( true );
		}

private class RichMapScreenTest extends MainScreen {

	/**
	 * The map field that will be displayed on the screen.
	 */
	RichMapScreenTest(double DEFAULT_LAT, double DEFAULT_LONG) {
		 
	        add(map);
	        
	        
	        Mapdata.add((Mappable) julieHome );
	        map.getMapField().update( true );  // To automatically update zoom and center point
	}
}
}

 

------------------------------------------------------------------------------------------------
Click "Accept as Solution" if post was what you needed. Give kudos if you feel response is helpful.

Please use plain text.
Contributor
UKSpike
Posts: 25
Registered: ‎04-07-2011
My Device: All
My Carrier: Any

Re: Refreshing Blackberry maps

Excellent- thanks very much!

Please use plain text.