import javax.microedition.location.Coordinates;
import net.rim.device.api.lbs.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
public class MapFielddemo extends UiApplication
{
public static void main(String[] args)
{
MapFielddemo theApp = new MapFielddemo();
theApp.enterEventDispatcher();
}
MapFielddemo()
{
pushScreen(new myScreen());
}
}
class myScreen extends FullScreen implements FieldChangeListener
{
private MapField _mapField;
private ButtonField _zoomIn;
private ButtonField _zoomOut;
private double _prevLat = 30.721596105585;
private double _prevLon = 76.710104942322;// positions of city in india, so if you want to try it please zoom out when you run this code.
private int _prevZoom = 4;
myScreen()
{
super(DEFAULT_MENU | DEFAULT_CLOSE);
createUI();
}
private void createUI()
{
Coordinates cord = new Coordinates(_prevLat,_prevLon,0);
VerticalFieldManager vfm;
synchronized (Application.getEventLock())
{
vfm = new VerticalFieldManager
(Manager.USE_ALL_WIDTH | Manager.USE_ALL_HEIGHT);
_mapField = new MapField();
_mapField.setPreferredSize(_mapField.getPreferredWidth(),
(int)(Display.getHeight() * 0.91));
vfm.add(_mapField);
}
FlowFieldManager ffm = new FlowFieldManager();
ffm.add(_zoomIn = new ButtonField("Zoom In",ButtonField.CONSUME_CLICK));
_zoomIn.setChangeListener(this);
ffm.add(_zoomOut = new ButtonField("Zoom Out",ButtonField.CONSUME_CLICK));
_zoomOut.setChangeListener(this);
vfm.add(ffm);
add(vfm);
_mapField.moveTo(cord);
_mapField.setZoom(_prevZoom);
}
public void fieldChanged(Field field, int context)
{
if (field == _zoomIn)
{
_mapField.setZoom(Math.max(_mapField.getZoom() - 1,
_mapField.getMinZoom()));
}
else if (field == _zoomOut)
{
_mapField.setZoom(Math.min(_mapField.getZoom() + 1,
_mapField.getMaxZoom()));
}
}
}
Thank you very much for your example. It helped me immensely. I am very new to bb programming. I wanted to know what should I use to get vertical scroll bar to zoom in or zoom out instead of buttons.
ReplyDelete- Shishir
hi i have applied your code and when i run this demo i got "No Data" in blackberry simulator. i am new to blackberry development.
ReplyDeleteplease help as soon as possible to resolve this issue.
Hi there, I have a query. I am working on Blackberry MapField for JDE 6.0 and above. ie. the net.rim.device.api.lbs.maps.ui.RichMapField.
ReplyDeleteAlthough I find an API to setZoom level through the richMapField.getMapField().getAction().setZoom(5), there aint any API to getZoom level.
Please help if you know of some workaround!
Thanks!
nice example ......
ReplyDeleteHi I am a blackberry developer. I am using static map image for showing map can i use your code for showing map, i am using blackberry os 5.0.0 and i have to show multiple location on s single map.
ReplyDeleteThanks in advance.