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

BlackBerry 6 Features: MapFactory

by BlackBerry Development Advisor (Retired) on ‎08-03-2010 11:22 AM - edited on ‎09-20-2010 05:05 PM by BlackBerry Development Advisor (13,299 Views)

MapFactory is class available with BlackBerry OS 6.0 that can generate static maps and an interactive RichMapField.  The MapFactory greatly reduced the effort required to get a map into an application and no sacrifices need to be made since the underlying MapField is always accessible using RichMapField.getMapField(). 

 

Static Maps

Static maps can easily be created using the MapFactory class. Since the class will generate a static bitmap, all the configuration information must be passed at the initial creation point.  We will use the MapDimension class to specify the map dimensions, zoom level and center point.  If we have data points on the map that we need to display we can use the MapDataModel class.

 

Here is an example of how we can generate and display a static map.

 

 

// Set the properties of the map using MapDimensions
MapDimensions md = new MapDimensions(320, 320);
md.setZoom(3); //Zoom Level 3 is between city level and street level
md.setCentre(new MapPoint(45.504512, -73.557029));
 
// Set the data that we want to display on the map
MapDataModel data = new MapDataModel();
MapLocation dataPoint1 = new MapLocation(45.504512, -73.557029,
"Notre Dame Basilica", null);
 
int cId = data.add((Mappable) dataPoint1, "Basilica");
data.tag(cId, "Church"); // locations can have more than one tag
data.setVisible( "Church" ); //We can hide or show each tag
 
//Create the map using our two objects
Bitmap map = MapFactory.getInstance().generateStaticMapImage(md, data);
 
//Add the bitmap to the current manager
add(new BitmapField(map));  

 

 

 

 

The above code will produce the following screen:

 screen1.png

 

 

 

Interactive Maps

Creating a rich map is just as easy as a static map.   A rich map is an interactive map field that the user can control.  The user is able to pan and zoom within the field while new map data is streamed over the internet in real time.  Here is the code:

 

 

//Generate a RichMapField using MapFactory
RichMapField map = MapFactory.getInstance().generateRichMapField();
//Retrieve the underlying MapField so we can configure it
MapField mapField = map.getMapField();
 
//Set the properties of the map using MapDimensions
MapDimensions md = new MapDimensions(320, 320);
md.setZoom(3);
md.setCentre(new MapPoint(45.504512, -73.557029));
mapField.setDimensions(md);
 
// Set the data that we want to display on the map
MapDataModel data = new MapDataModel();
MapLocation dataPoint1 = new MapLocation(45.504512, -73.557029,
"Notre Dame Basilica", null);
 
int cId = data.add((Mappable) dataPoint1, "Basilica");
data.tag(cId, "Church"); // locations can have more than one tag
data.setVisible( "Church" );
mapField.setModel(data);
//Call mapField.update() to ensure the new map data is reflected on the display
mapField.update();
add(map);
 

 

 

 

This code will produce the following screen:

 screen2.PNG

 

Be sure to view the attached source code for a complete sample application that demonstrates the two concepts that were described above.

Contributors
Comments
by Developer on ‎08-21-2011 06:00 PM

Hi,

 

Can you please give and idea to listen for click event on a pin? This will be a great help as I serched on a forum and all resources no answer for this question. 

Polpulating mutiple pins and able to listen for click event will be a great topic for an article that helps a lot for everyone.

 

 

Many Thanks

Users Online
Currently online: 23 members 1,107 guests
Please welcome our newest community members: