// -------- ------------------- ------------- --------------------------
// 28JAN2011 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////////
/**
* Map routing demo for Guidebee Map API on MIDP platform.
*/
public class MapRoutingMIDP extends MapDemoMIDP implements CommandListener,
IRoutingListener {
private Command mapGetDirectionCommand = new Command("Get Direction",
Command.OK, 1);
public void startApp() {
init();
canvas.addCommand(mapGetDirectionCommand);
map.setRoutingListener(this);
canvas.setCommandListener(this);
GeoLatLng center = new GeoLatLng(-31.948275, 115.857562);
map.setCenter(center, 13, MapType.GOOGLEMAP);
Display.getDisplay(this).setCurrent(canvas);
}
public void commandAction(Command c, Displayable d) {
if (c == mapGetDirectionCommand) {
String name1 = " ";
String name2 = " ";
map.getDirections("from: " + name1 + " to: " + name2);
}
}
public void done(String query, MapDirection result) {
if (result != null) {
map.setMapDirection(result);
map.resize(result.getBound());
map.setZoom(3);
}
}
}

地图服务可以选择使用Google 地图服务,CloudMade地图服务,在中国还可能选择MapAbc地图服务,缺省使用Google 地图服务。
getDirections()具有三个重载函数,例子中是采用的文字描述方式。上述示例采用了from: address1 to: address2 的格式, CloudMade地图服务和MapAbc地图服务则必需采用 经度1,纬度1,经度2,纬度2和格式。
为避免混淆,可以使用下述格式。
public void getDirection(GeoLatLng[] waypoints, IRoutingListener listener);
其中 waypoints 为途径点坐标数组经纬值,可以支持多点路径查询。
此外对于MapAbc 地图服务,还可以指定城市编码,如南京编码为25。
public void getDirection(int citycode,String query, IRoutingListener
作者:mapdigit