Android 路徑查詢

來源:互聯網
上載者:User

   可以通過RasterMap的getDirection()方法來查詢路徑,和查詢地址類似,路徑查詢的結果也是通過回呼函數的方式來通知應用程式的,下面的例子返回南京到北京的路徑。返回結果存放在MapDirection中,MapDirection包含了路徑的詳細資料,包括路徑的每個步驟,長度,時間,方向等。

  Java代碼:

  packageeoe.demo;

  importcom.mapdigit.gis.MapDirection;

  importcom.mapdigit.gis.MapPoint;

  importcom.mapdigit.gis.geometry.GeoLatLng;

  importcom.mapdigit.gis.service.IRoutingListener;

  importcom.pstreets.gisengine.R;

  importcom.pstreets.gisengine.SharedMapInstance;

  importandroid.app.Activity;

  importandroid.os.Bundle;

  importandroid.view.Menu;

  importandroid.view.MenuInflater;

  importandroid.view.MenuItem;

  publicclassMapRoutingextendsActivityimplementsIRoutingListener{

  @Override

  publicvoidonCreate(BundlesavedInstanceState){

  super.onCreate(savedInstanceState);

  setContentView(R.layout.main);

  }

  @Override

  publicvoidonStart(){

  super.onStart();

  GeoLatLngcenter=newGeoLatLng(32.0616667,118.7777778);

  SharedMapInstance.map.setCenter(center,15,

  com.mapdigit.gis.raster.MapType.MICROSOFTCHINA);

  SharedMapInstance.map.setRoutingListener(this);

  }

  @Override

  publicbooleanonCreateOptionsMenu(Menumenu){

  MenuInflaterinflater=getMenuInflater();

  inflater.inflate(R.menu.maprouting_menu,menu);

  returntrue;

  }

  @Override

  publicbooleanonOptionsItemSelected(MenuItemitem){

  //Handleitemselection

  switch(item.getItemId()){

  caseR.id.getdirection:

  Stringname1="南京";

  Stringname2="北京";

  SharedMapInstance.map.getDirections("from:"+name1+"to:"

  +name2);

  returntrue;

  default:

  returnsuper.onOptionsItemSelected(item);

  }

  }

  @Override

  publicvoiddone(Stringquery,MapDirectionresult){

  if(result!=null){

  SharedMapInstance.map.setMapDirection(result);

  SharedMapInstance.map.resize(result.getBound());

  SharedMapInstance.map.zoomOut();

  SharedMapInstance.map.zoomOut();

  }

  }

  @Override

  publicvoidreadProgress(intbytes,inttotal){

  }

  }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.