One can draw pin over the map and click on each pin to perform a particular task like going to the subsequent screen, view address etc. It’s easy to achieve this task on touch devices but performing same task in non touch device has its own difficulties associated with it. To achieve this, one can use the code given below.
We are showing a small circle (a PNG image) in the centre of the map. One need to scroll top / bottom or right / left and place a pin in the centre of the map then on click you will be able to perform a particular task .
Now coming to touch device, if you are using your own map class, I have read in many forum and blog that it’s not possible and very difficult to scroll the map. Here is a simple solution to achieve this. You can scroll the entire map by using the code given below.

Blackberry Non Touch Device Mapping Pins
===================================================================
public class MapScreen extends MainScreen implements
FocusChangeListener, FieldChangeListener {
private DemoMapField _mapField;;
public MapScreen(){
// TODO something.
}
protected boolean keyChar(char c, int status, int time) {
if (c == ‘!’) {// Zoom In
_mapField.setZoom(Math.max(_mapField.getZoom() - 1,
_mapField.getMinZoom()));
}
return true;
} else if (c == ‘@’) {// Zoom out
_mapField.setZoom(Math.min(_mapField.getZoom() + 1,
_mapField.getMaxZoom()));
}
return true;
}
return super.keyChar(c, status, time);
}
protected boolean navigationMovement(int dx, int dy, int status, int time) {
return _mapField.navigationMovement(dx, dy, status, time, this);
}
return true;
}
protected boolean navigationClick(int status, int time) {
// Call : _mapField.getHighlightedLocation();
//TODO Something
return true;
}
protected boolean touchEvent(TouchEvent message) {
boolean isConsumed = false;
try{
if (message.getEvent() == TouchEvent.CLICK) {
super.touchEvent(message);
_ mapField.setFocus();
HandleMapClick(message);
}
}
}catch (Exception e) {
}
try{
TouchGesture touchGesture = message.getGesture();
if (touchGesture!=null && touchGesture.getEvent() == TouchGesture.SWIPE)
{
if (touchGesture.getSwipeDirection() == TouchGesture.SWIPE_EAST) {
for (int index = 0; index < 6; index++)
navigationMovement(-index, 0, 1, 0);
return true;
}
if (touchGesture.getSwipeDirection() == TouchGesture.SWIPE_NORTH) {
for (int index = 0; index < 6; index++)
navigationMovement(0, index, 1, 0);
return true;
}
if (touchGesture.getSwipeDirection() == TouchGesture.SWIPE_SOUTH) {
for (int index = 0; index < 6; index++)
navigationMovement(0, -index, 1, 0);
return true;
}
if (touchGesture.getSwipeDirection() == TouchGesture.SWIPE_WEST) {
for (int index = 0; index < 6; index++)
navigationMovement(index, 0, 1, 0);
return true;
}
}
}catch (Throwable e) {
}
return isConsumed;
}
private void HandleMapClick(TouchEvent message) {
try {
_mapField.setClick(message);
// Call : _mapField.getHighlightedLocation();
//TODO Something
} catch (Exception e) {
}
}
***************************************************************************
public class DemoMapField extends MapField{
private Vector _allLocations = new Vector();
private MapLocation _highlightedLocation;
private Bitmap bmpCursor = Bitmap.getBitmapResource(“highlighted circle image”);
private Bitmap bmpPinRed = Bitmap.getBitmapResource(“an png image- pin”);
private Bitmap bmpPinBlue = Bitmap.getBitmapResource(“an png image-pin “);
protected void paint(Graphics g) {
g.setDrawingStyle(Graphics.DRAWSTYLE_AAPOLYGONS, true);
super.paint(g);
if (!Touchscreen.isSupported()) {
determineSelectedLocation(new XYPoint(getWidth() >> 1,
getHeight() >> 1));
g.drawBitmap((getWidth() - bmpCursor.getWidth()) >> 1,
(getHeight() - bmpCursor.getHeight()) >> 1, getWidth(),
getHeight(), bmpCursor, 0, 0);
}
if (this.currentLocation != null) {
MapLocation currentSite = new MapLocation(this.currentLocation[0],
this.currentLocation[1], “”, “”, “”, “”);
drawSite(g, currentSite, bmpPinRed);
}
for (int count = 0; count < _allLocations.size(); count++) {
MapLocation currentSite = (MapLocation) _allLocations
.elementAt(count);
drawSite(g, currentSite, bmpPinBlue);
}
g.setColor(Color.BLACK);
g.drawText(“Use ‘!’ to zoom in”, 1,
g.getFont().getHeight() + 2);
g.drawText(“Use ‘@’ to zoom out”, 1,
(g.getFont().getHeight() * 2) + 4);
}
public void determineSelectedLocation(XYPoint colisionWith) {
if (_allLocations == null || _allLocations.size() == 0)
return;
XYPoint[] locationsXY = new XYPoint[_allLocations.size()];
for (int count = 0; count < locationsXY.length; count++) {
MapLocation currentSite = (MapLocation) _allLocations
.elementAt(count);
Coordinates co = new Coordinates(currentSite.getLatitude(),
currentSite.getLongitude(), 0);
XYPoint p = new XYPoint();
convertWorldToField(co, p);
locationsXY[count] = p;
}
int closerIndex = 0;
int closerValue = getDiff(colisionWith, locationsXY[0]);
for (int i = 1; i < locationsXY.length; i++) {
int diff = getDiff(colisionWith, locationsXY[i]);
if (diff < closerValue) {
closerValue = diff;
closerIndex = i;
}
}
if (closerValue <= 60) {
_highlightedLocation = (MapLocation) _allLocations
.elementAt(closerIndex);
} else {
_highlightedLocation = null;
}
}
private int getDiff(XYPoint p1, XYPoint p2) {
return Math.abs(Math.abs(p1.x) - Math.abs(p2.x))
+ Math.abs(Math.abs(p1.y) - Math.abs(p2.y));
}
void drawSite(Graphics g, MapLocation currentSite, Bitmap bmp) {
Coordinates co = new Coordinates(currentSite.getLatitude(),
currentSite.getLongitude(), 0);
XYPoint point = new XYPoint();
convertWorldToField(co, point);
if (!(point.x < 0 || point.x > getWidth() || point.y < 0 || point.y > getHeight())) {
g.drawBitmap(point.x - 5, point.y - bmp.getHeight() + 10,
bmp.getWidth(), bmp.getHeight(), bmp, 0, 0);
}
}
public void setZoom(int zoom) {
super.setZoom(zoom);
}
public boolean navigationMovement(int dx, int dy, int s, int t,
MainScreen mainScreen) {
int zoom = getZoom();
int latitude = getLatitude() - ((dy << 3) << zoom); // << 3 is
int longitude = getLongitude() + ((dx << 3) << zoom);
{
moveTo(latitude, longitude);
}
return true;
}
private boolean FindMaximum(double latitude, int dx, int dy, int zoom) {
double minLat = Double.MAX_VALUE;
for (int i = 0; i < _allLocations.size(); i++) {
MapLocation location = (MapLocation) _allLocations.elementAt(i);
if (location.getLatitude() < minLat)
minLat = location.getLatitude();
}
if (minLat < latitude)
return false;
else
return true;
}
private boolean FindMinimum(double latitude, int dx, int dy, int zoom) {
double maxLat = Double.MIN_VALUE;
for (int i = 0; i < _allLocations.size(); i++) {
MapLocation location = (MapLocation) _allLocations.elementAt(i);
if (location.getLatitude() > maxLat)
maxLat = location.getLatitude();
}
if (maxLat > latitude)
return false;
else
return true;
}
protected boolean touchEvent(TouchEvent message) {
if (message.getEvent() == TouchEvent.CLICK) {
int x = message.getX(1) - getLeft();
int y = message.getY(1) - getTop();
determineSelectedLocation(new XYPoint(x, y));
return true;
}
return super.touchEvent(message);
}
void addSite(MapLocation site) {
_allLocations.addElement(site);
}
public void setLocations(Vector allLocations) {
this._allLocations = allLocations;
}
public MapLocation getHighlightedLocation() {
return _highlightedLocation;
}
private double[] currentLocation = null;
public void setCurrentLocation(double[] currentLocation) {
this.currentLocation = currentLocation;
}
public void setClick(TouchEvent message) {
touchEvent(message);
}
}