android笔记---百度地图api应用 (二) 获取公交路线的详细信息
package com.example.bdtest; import com.baidu.mapapi.MKEvent;
import com.baidu.mapapi.MKPlanNode;
import com.baidu.mapapi.MKPoiInfo;
import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.GeoPoint;
import com.baidu.mapapi.MKAddrInfo;
import com.baidu.mapapi.MKBusLineResult;
import com.baidu.mapapi.MKDrivingRouteResult;
import com.baidu.mapapi.MKPoiResult;
import com.baidu.mapapi.MKSearch;
import com.baidu.mapapi.MKSuggestionResult;
import com.baidu.mapapi.MKTransitRouteResult;
import com.baidu.mapapi.MKWalkingRouteResult;
import com.baidu.mapapi.MapActivity;
import com.baidu.mapapi.MapController;
import com.baidu.mapapi.MapView;
import com.baidu.mapapi.PoiOverlay;
import com.baidu.mapapi.RouteOverlay; import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Toast; public class MainActivity extends MapActivity { private BMapManager mBMapMan = null;
private MapView mMapView = null;
private MKSearch mMKSearch = null;
private String mCityName = null; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBMapMan=new BMapManager(getApplication());
mBMapMan.init("3B910277809EF23A5FAFAB66F09168D73CB3B793", null);
//注意:请在试用setContentView前初始化BMapManager对象,否则会报错
setContentView(R.layout.activity_main);
super.initMapActivity(mBMapMan);
mMKSearch = new MKSearch();
mMKSearch.init(mBMapMan, new MySearchListener(){ @Override
public void onGetAddrResult(MKAddrInfo arg0, int arg1) {
// TODO Auto-generated method stub
super.onGetAddrResult(arg0, arg1);
} public void onGetBusDetailResult(MKBusLineResult result, int iError) {
if (iError != 0 || result == null) {
Toast.makeText(MainActivity.this, "抱歉,未找到结果", Toast.LENGTH_LONG).show();
return;
}
RouteOverlay routeOverlay = new RouteOverlay(MainActivity.this, mMapView); // 此处仅展示一个方案作为示例
routeOverlay.setData(result.getBusRoute());
mMapView.getOverlays().clear();
mMapView.getOverlays().add(routeOverlay);
mMapView.refreshDrawableState();
mMapView.getController().animateTo(result.getBusRoute().getStart());
} @Override
public void onGetDrivingRouteResult(MKDrivingRouteResult result, int iError) {
if (result == null) {
return;
}
RouteOverlay routeOverlay = new RouteOverlay(MainActivity.this, mMapView); // 此处仅展示一个方案作为示例
routeOverlay.setData(result.getPlan(0).getRoute(0));
mMapView.getOverlays().add(routeOverlay);
mMapView.refreshDrawableState();
} @Override
public void onGetPoiDetailSearchResult(int arg0, int arg1) {
// TODO Auto-generated method stub
super.onGetPoiDetailSearchResult(arg0, arg1);
} @Override
public void onGetPoiResult(MKPoiResult res, int type, int error) {
// 错误号可参考MKEvent中的定义
if (error != 0 || res == null) {
Toast.makeText(MainActivity.this, "抱歉,未找到结果", Toast.LENGTH_LONG).show();
return;
}
// 找到公交路线poi node
MKPoiInfo curPoi = null;
int totalPoiNum = res.getNumPois();
for(int idx = 0; idx<totalPoiNum; idx++ ) {
curPoi = res.getPoi(idx);
if ( 2 == curPoi.ePoiType ) {
break;
}
}
mMKSearch.busLineSearch(mCityName, curPoi.uid);
} @Override
public void onGetRGCShareUrlResult(String arg0, int arg1) {
// TODO Auto-generated method stub
super.onGetRGCShareUrlResult(arg0, arg1);
} @Override
public void onGetSuggestionResult(MKSuggestionResult arg0, int arg1) {
// TODO Auto-generated method stub
super.onGetSuggestionResult(arg0, arg1);
} @Override
public void onGetTransitRouteResult(MKTransitRouteResult arg0,
int arg1) {
// TODO Auto-generated method stub
super.onGetTransitRouteResult(arg0, arg1);
} @Override
public void onGetWalkingRouteResult(MKWalkingRouteResult arg0,
int arg1) {
// TODO Auto-generated method stub
super.onGetWalkingRouteResult(arg0, arg1);
} @Override
protected Object clone() throws CloneNotSupportedException {
// TODO Auto-generated method stub
return super.clone();
} @Override
public boolean equals(Object o) {
// TODO Auto-generated method stub
return super.equals(o);
} @Override
protected void finalize() throws Throwable {
// TODO Auto-generated method stub
super.finalize();
} @Override
public int hashCode() {
// TODO Auto-generated method stub
return super.hashCode();
} @Override
public String toString() {
// TODO Auto-generated method stub
return super.toString();
} });//注意,MKSearchListener只支持一个,以最后一次设置为准 mMapView=(MapView)findViewById(R.id.bmapView);
mMapView.setBuiltInZoomControls(true);
//设置启用内置的缩放控件
MapController mMapController=mMapView.getController();
// 得到mMapView的控制权,可以用它控制和驱动平移和缩放
GeoPoint point =new GeoPoint((int)(39.915* 1E6),(int)(116.404* 1E6));
//用给定的经纬度构造一个GeoPoint,单位是微度 (度 * 1E6)
mMapController.setCenter(point);//设置地图中心点
mMapController.setZoom(12);//设置地图zoom级别 //显示交通信息图
//mMapView.setTraffic(true); //显示卫星图
//mMapView.setSatellite(true); //检索北京西站与北京北站为顶点所确定的距形区域内的KFC餐厅
// // 北京西站
// GeoPoint ptLB = new GeoPoint( (int)(39.901375 * 1E6),(int)(116.329099 * 1E6));
// // 北京北站
// GeoPoint ptRT = new GeoPoint( (int)(39.949404 * 1E6),(int)(116.360719 * 1E6));
// mMKSearch.poiSearchInbounds("KFC", ptLB, ptRT); //检索从天安门到百度大厦的驾车路线
// MKPlanNode start = new MKPlanNode();
// start.pt = new GeoPoint((int) (39.915 * 1E6), (int) (116.404 * 1E6));
// MKPlanNode end = new MKPlanNode();
// end.pt = new GeoPoint(40057031, 116307852);// 设置驾车路线搜索策略,时间优先、费用最少或距离最短
// mMKSearch.setDrivingPolicy(MKSearch.ECAR_TIME_FIRST);
// mMKSearch.drivingSearch(null, start, null, end); //获取公交路线的详细信息
mCityName = "北京";
mMKSearch.poiSearchInCity(mCityName, "717"); } @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} @Override
protected void onDestroy(){
if(mBMapMan!=null){
mBMapMan.destroy();
mBMapMan=null;
}
super.onDestroy();
}
@Override
protected void onPause(){
if(mBMapMan!=null){
mBMapMan.stop();
}
super.onPause();
}
@Override
protected void onResume(){
if(mBMapMan!=null){
mBMapMan.start();
}
super.onResume();
} @Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
} }
android笔记---百度地图api应用 (二) 获取公交路线的详细信息的更多相关文章
- android笔记---百度地图api应用 (一)
package com.example.bdtest; import com.baidu.mapapi.MKEvent; import com.baidu.mapapi.MKPlanNode; imp ...
- 【百度地图API】如何获取行政区域的边界?
原文:[百度地图API]如何获取行政区域的边界? 摘要:以前教过大家如何自行获取行政区域,或者自定义获取一个区域的边界值.今天来教大家直接调用百度地图API1.3(目前最新版本)来获取行政区域的边界值 ...
- 【百度地图API】自行获取区域经纬度的工具
原文:[百度地图API]自行获取区域经纬度的工具 摘要:上一章教大家如何建立自己的行政区域地图.这次为大家提供一个,可视化选择区域,并且能自动生成经纬度代码的工具.工具的源代码完全公开,并且做了详尽的 ...
- 百度地图API地点搜索-获取经纬度
分享一下地图上的地点搜索和鼠标点击获取地点经纬度,这些都是地图比较基本和实用的代码,其中还包括了根据用户IP进行地图的显示.改变地图上的鼠标样式.启用滚轮缩放等,算是半入门吧,其他的一些可以自己参考百 ...
- 简单几行代码使用百度地图API接口分页获取信息
首发于: 万能助手扩展开发:使用百度地图API接口分页获取信息_电脑计算机编程入门教程自学 http://jianma123.com/viewthread.aardio?threadid=426 使用 ...
- 【百度地图API】如何制作公交线路的搜索?如331路
原文:[百度地图API]如何制作公交线路的搜索?如331路 摘要: 从A点到B点的公交导航大家都知道怎么做了,那么单独查询331路公交车的公交路线,如何制作呢?我们一起来学习一下~ --------- ...
- android 基于百度地图api开发定位以及获取详细地址
一:百度地图开发必须要到百度开发平台android开发api下载相应的库,已经申请百度地图开发key. 二:新建项目baidumaplocation.设计main.xml文件这里注意的是MapView ...
- Android通过百度地图API用Service和Alarm在后台定时获取地理位置信息
本文主要介绍了Android项目集成百度地图API,使用AlarmManager定时调用Service,在Service中请求坐标更新,并通过坐标得到省.市和县三级地理位置信息的方法. 程序结构很简单 ...
- Android端百度地图API使用详解
百度地图API简介 百度地图移动版API(Android)是一套基于Android设备的应用程序接口,通过该接口,可以轻松的访问百度服务和数据,构建功能丰富.交互性强的地图应用程序. 百度地图移动版A ...
随机推荐
- Python是解释性语言吗? 直到看到有 python py、pyc、pyo、pyd 文件
py是源文件,pyc是源文件编译后的文件,pyo是源文件优化编译后的文件,pyd是其他语言写的python库 1. Python是一门解释型语言? Python是一门解释性语言,我就这样一直相信下去, ...
- 在Java中使用Kafka
Producer部分 Producer在实例化后, 对外提供send方法, 用于将数据送到指定的topic和partition; 以及在退出时需要的destroy方法. 接口 KafkaProduce ...
- 转:3d max 2013 安装教程,凭着一种互联网精神提供给广大朋友
看到有人在ps区咨询如何安装3d max教程,当你进行第一步之前,请先断开网络连接第一步:运行安装程序 第二步:接受安装协议,点击下一步会提示输入序列号 第三步:你会看到已经安装完成了的界面 第四部: ...
- ios中一级导航
效果图 第一步先下载文件 http://pan.baidu.com/share/link?shareid=2148445651&uk=9237761877 将目录引入到xcode中 在xcod ...
- rox + openbox + fbpanel + conky打造又快又稳的桌面
从开始用 Gentoo 以来,就没有打算用 gnome . KDE 这些巨无霸级别的 DE ,最后选择了相对来来说比较轻量级的 Xfce4 ,不过最近更是变本加厉,连 Xfce4 都觉得太大.于是,下 ...
- Swift 互斥锁写法
oc中的互斥锁@synchronized(self) { //需要执行的代码块} swift中的互斥锁objc_sync_enter(self)//需要执行的代码块objc_sync_exit(sel ...
- Kafka 如何读取指定topic中的offset -------------用来验证分区是不是均衡!!!(__consumer_offsets)(已验证!)
我现在使用的是librdkafka 的C/C++ 的客户端来生产消息,用flume来辅助处理异常的数据,,, 但是在前段时间,单独使用flume测试的时候发现,flume不能对分区进行负载均衡!同一个 ...
- VS2017 IDE开发工具选型、安装和使用
原文地址:https://blog.csdn.net/boonya/article/details/78739500 距离上次使用VS工具已是2年前了,这次准备选择比较新的版本来开发桌面程序了.总的来 ...
- ORA-65179: cannot keep datafiles for a pluggable database that is not unplugged
SQL> drop pluggable database pdb2; drop pluggable database pdb2 * ERROR at line : ORA-: cannot ke ...
- mysql的内存使用
Mysql Server Memory Usage = Sum of Global Buffers + (number of Connection * Per thread memory variab ...