Blackberry引路蜂地图开发示例:路径查询

可以通过RasterMap的getDirection()方法来查询路径,和查询地址类似,路径查询的结果也是通过回调函数的方式来通知应用程序的,下面的例子返回南京到北京的路径。返回结果存放在MapDirection中,MapDirection包含了路径的详细信息,包括路径的每个步骤,长度,时间,方向等

//--------------------------------- PACKAGE ------------------------------------
package com.pstreets.gisengine.demo.rim; 
 
//--------------------------------- IMPORTS ------------------------------------
import com.mapdigit.gis.MapDirection;
import com.mapdigit.gis.geometry.GeoLatLng;
import com.mapdigit.gis.raster.MapType;
import com.mapdigit.gis.service.IRoutingListener;
import com.pstreets.gisengine.demo.MapDemoRIM;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.MenuItem; 
 
//[------------------------------ MAIN CLASS ----------------------------------]
/**
 *  Map routing demo for Guidebee Map API on RIM platform.
 * <hr><b>© Copyright 2011 Guidebee, Inc. All Rights Reserved.</b>
 * @version     1.00, 10/02/11
 * @author      Guidebee Pty Ltd.
 */
public class MapRoutingRIM extends MapDemoRIM implements    IRoutingListener { 
 
    /**
     * Entry point for application
     * @param args Command line arguments (not used)
     */
    public static void main(String[] args)
    {
        // Create a new instance of the application and make the currently
        // running thread the application's event dispatch thread.
        MapRoutingRIM theApp = new MapRoutingRIM();      
        theApp.enterEventDispatcher();
    }
    
    private MenuItem mapGetDirectionMenuItem = new MenuItem("Get Direction", 0, 0){
        public void run(){
            String name1 = "南京";           
            String name2 = "北京";           
            map.getDirections("from: " + name1 + " to: " + name2);
        }
    }; 
 
    public MapRoutingRIM() { 
 
        init();
        pushScreen(canvas);
        map.setRoutingListener(this);
        GeoLatLng center = new GeoLatLng(32.0616667, 118.7777778);       
        map.setCenter(center, 13, MapType.MICROSOFTCHINA);
        
    } 
 
    public void done(String arg0, MapDirection result) {
        if (result != null) {
            map.setMapDirection(result);
            map.resize(result.getBound());
            map.setZoom(5);
        }
    }
    
    protected void createMenu(Menu menu, int instance){
         menu.add(mapGetDirectionMenuItem); 
 
   }
}


 

地图服务可以选择使用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 listener);

Blackberry引路蜂地图开发包Ver2.1下载


 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值