android 开发(百度地图)
百度地图开放平台:http://lbsyun.baidu.com/
百度地图API:http://developer.baidu.com/map/reference/
Android地图SDK
百度地图LBS云是百度地图针对LBS开发者全新推出的平台级服务,不仅适用PC应用开发,同时适用移动设备应用的开发。使用LBS云,可以实现移动开发者存储海量位置数据的服务器零成本及维护压力,且支持高效检索用户数据,且实现地图展现。
开发者指南
eclipse数字签名:windows->perferences->android->build->SHA1 fingerprint
相关下载-〉自定义下载-〉开发包、类参考、示例代码
找到JAR包拷贝到 libs里
SO包里按开发类型选择拷贝到libs里(如:x86、armeapi)
集成地图SDK的应用,在打包混淆的时候,需要注意与地图SDK相关的方法不可被混淆。混淆方法如下:
-keep class com.baidu.** {*;}
-keep class vi.com.** {*;}
-dontwarn com.baidu.**
保证百度类不能被混淆,否则会出现网络不可用等运行时异常
清单文件中添加
<application>
<meta-data
android:name="com.baidu.lbsapi.API_KEY"
android:value="开发者 key" />
</application>
2)添加所需权限
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
在布局xml文件中添加地图控件;
<com.baidu.mapapi.map.MapView
android:id="@+id/bmapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" />
在应用程序创建时初始化 SDK引用的Context 全局变量:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//在使用SDK各组件之前初始化context信息,传入ApplicationContext
//注意该方法要再setContentView方法之前实现
SDKInitializer.initialize(getApplicationContext());
setContentView(R.layout.activity_main);
}
}
注意:在SDK各功能组件使用之前都需要调用
SDKInitializer.initialize(getApplicationContext());,因此我们建议该方法放在Application的初始化方法中
创建地图Activity,管理地图生命周期;
public class MainActivity extends Activity {
MapView mMapView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//在使用SDK各组件之前初始化context信息,传入ApplicationContext
//注意该方法要再setContentView方法之前实现
SDKInitializer.initialize(getApplicationContext());
setContentView(R.layout.activity_main);
//获取地图控件引用
mMapView = (MapView) findViewById(R.id.bmapView);
}
@Override
protected void onDestroy() {
super.onDestroy();
//在activity执行onDestroy时执行mMapView.onDestroy(),实现地图生命周期管理
mMapView.onDestroy();
}
@Override
protected void onResume() {
super.onResume();
//在activity执行onResume时执行mMapView. onResume (),实现地图生命周期管理
mMapView.onResume();
}
@Override
protected void onPause() {
super.onPause();
//在activity执行onPause时执行mMapView. onPause (),实现地图生命周期管理
mMapView.onPause();
}
}
完成以上步骤后,运行程序,即可显示地图。
public LocationClient mLocationClient = null;
public BDLocationListener myListener = new MyLocationListener(); 在onCreate方法中添加
mLocationClient = new LocationClient(getApplicationContext()); //声明LocationClient类
mLocationClient.registerLocationListener( myListener ); //注册监听函数
配置定位SDK参数
private void initLocation(){
LocationClientOption option = new LocationClientOption();
option.setLocationMode(LocationMode.Hight_Accuracy
);//可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
option.setCoorType("bd09ll");//可选,默认gcj02,设置返回的定位结果坐标系
int span=1000;
option.setScanSpan(span);//可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的
option.setIsNeedAddress(true);//可选,设置是否需要地址信息,默认不需要
option.setOpenGps(true);//可选,默认false,设置是否使用gps
option.setLocationNotify(true);//可选,默认false,设置是否当GPS有效时按照1S/1次频率输出GPS结果
option.setIsNeedLocationDescribe(true);//可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
option.setIsNeedLocationPoiList(true);//可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
option.setIgnoreKillProcess(false);//可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死
option.SetIgnoreCacheException(false);//可选,默认false,设置是否收集CRASH信息,默认收集
option.setEnableSimulateGps(false);//可选,默认false,设置是否需要过滤GPS仿真结果,默认需要
mLocationClient.setLocOption(option);
}
实现BDLocationListener接口
BDLocationListener为结果监听接口,异步获取定位结果,实现方式如下:
public class MyLocationListener implements BDLocationListener { @Override
public void onReceiveLocation(BDLocation location) {
//Receive Location
StringBuffer sb = new StringBuffer(256);
sb.append("time : ");
sb.append(location.getTime());
sb.append("\nerror code : ");
sb.append(location.getLocType());
sb.append("\nlatitude : ");
sb.append(location.getLatitude());
sb.append("\nlontitude : ");
sb.append(location.getLongitude());
sb.append("\nradius : ");
sb.append(location.getRadius());
if (location.getLocType() == BDLocation.TypeGpsLocation){// GPS定位结果
sb.append("\nspeed : ");
sb.append(location.getSpeed());// 单位:公里每小时
sb.append("\nsatellite : ");
sb.append(location.getSatelliteNumber());
sb.append("\nheight : ");
sb.append(location.getAltitude());// 单位:米
sb.append("\ndirection : ");
sb.append(location.getDirection());// 单位度
sb.append("\naddr : ");
sb.append(location.getAddrStr());
sb.append("\ndescribe : ");
sb.append("gps定位成功"); } else if (location.getLocType() == BDLocation.TypeNetWorkLocation){// 网络定位结果
sb.append("\naddr : ");
sb.append(location.getAddrStr());
//运营商信息
sb.append("\noperationers : ");
sb.append(location.getOperators());
sb.append("\ndescribe : ");
sb.append("网络定位成功");
} else if (location.getLocType() == BDLocation.TypeOffLineLocation) {// 离线定位结果
sb.append("\ndescribe : ");
sb.append("离线定位成功,离线定位结果也是有效的");
} else if (location.getLocType() == BDLocation.TypeServerError) {
sb.append("\ndescribe : ");
sb.append("服务端网络定位失败,可以反馈IMEI号和大体定位时间到loc-bugs@baidu.com,会有人追查原因");
} else if (location.getLocType() == BDLocation.TypeNetWorkException) {
sb.append("\ndescribe : ");
sb.append("网络不同导致定位失败,请检查网络是否通畅");
} else if (location.getLocType() == BDLocation.TypeCriteriaException) {
sb.append("\ndescribe : ");
sb.append("无法获取有效定位依据导致定位失败,一般是由于手机的原因,处于飞行模式下一般会造成这种结果,可以试着重启手机");
}
sb.append("\nlocationdescribe : ");
sb.append(location.getLocationDescribe());// 位置语义化信息
List<Poi> list = location.getPoiList();// POI数据
if (list != null) {
sb.append("\npoilist size = : ");
sb.append(list.size());
for (Poi p : list) {
sb.append("\npoi= : ");
sb.append(p.getId() + " " + p.getName() + " " + p.getRank());
}
}
Log.i("BaiduLocationApiDem", sb.toString());
}
启用
mLocationClient.start();
启动后,因为设置了mLocationClient.registerLocationListener(myListener); // 注册监听函数
所以myListener会调用private class MyLocationListener implements BDLocationListener {里的onReceiveLocation方法返回结果
private class MyLocationListener implements BDLocationListener { @Override
public void onReceiveLocation(BDLocation location) {
if (isFirst) {
// 让地图中心跑到我的真实位置处
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
MapStatusUpdate mapStatusUpdate = MapStatusUpdateFactory.newLatLngZoom(latLng, 12);
// 没有动画效果
// mBaiduMap.setMapStatus(mapStatusUpdate);
mBaiduMap.animateMapStatus(mapStatusUpdate, 1000);
isFirst = false;
} mCurrentLocation = location;
String addrStr = location.getAddrStr();
tv_info.setText(addrStr); // Receive Location
/*
* StringBuffer sb = new StringBuffer(256); sb.append("time : ");
* sb.append(location.getTime()); sb.append("\nerror code : ");
* sb.append(location.getLocType()); sb.append("\nlatitude : ");
* sb.append(location.getLatitude()); sb.append("\nlontitude : ");
* sb.append(location.getLongitude()); // 定位的可能范围
* sb.append("\nradius : "); sb.append(location.getRadius()); if
* (location.getLocType() == BDLocation.TypeGpsLocation) {// GPS定位结果
* sb.append("\nspeed : "); sb.append(location.getSpeed());//
* 单位:公里每小时 授时 4颗 // 2 1位置服务站 // 双向定位 sb.append("\nsatellite : ");
* sb.append(location.getSatelliteNumber());
* sb.append("\nheight : "); sb.append(location.getAltitude());//
* 单位:米 sb.append("\ndirection : ");
* sb.append(location.getDirection());// 单位度 sb.append("\naddr : ");
* sb.append(location.getAddrStr()); sb.append("\ndescribe : ");
* sb.append("gps定位成功");
*
* } else if (location.getLocType() ==
* BDLocation.TypeNetWorkLocation) {// 网络定位结果
* sb.append("\naddr : "); sb.append(location.getAddrStr()); //
* 运营商信息 sb.append("\noperationers : ");
* sb.append(location.getOperators());// 0 1 2
* sb.append("\ndescribe : "); sb.append("网络定位成功"); } else if
* (location.getLocType() == BDLocation.TypeOffLineLocation) {//
* 离线定位结果 sb.append("\ndescribe : ");
* sb.append("离线定位成功,离线定位结果也是有效的"); } else if (location.getLocType()
* == BDLocation.TypeServerError) { sb.append("\ndescribe : ");
* sb.append
* ("服务端网络定位失败,可以反馈IMEI号和大体定位时间到loc-bugs@baidu.com,会有人追查原因"); } else
* if (location.getLocType() == BDLocation.TypeNetWorkException) {
* sb.append("\ndescribe : "); sb.append("网络不同导致定位失败,请检查网络是否通畅"); }
* else if (location.getLocType() ==
* BDLocation.TypeCriteriaException) { sb.append("\ndescribe : ");
* sb
* .append("无法获取有效定位依据导致定位失败,一般是由于手机的原因,处于飞行模式下一般会造成这种结果,可以试着重启手机");
* } sb.append("\nlocationdescribe : ");
* sb.append(location.getLocationDescribe());// 位置语义化信息 List<Poi>
* list = location.getPoiList();// POI数据 if (list != null) {
* sb.append("\npoilist size = : "); sb.append(list.size()); for
* (Poi p : list) { sb.append("\npoi= : "); sb.append(p.getId() +
* " " + p.getName() + " " + p.getRank()); } }
*/
// Log.d("tag", sb.toString());
}
}
MyLocationListener
关闭
protected void onDestroy() {
super.onDestroy();
// 在activity执行onDestroy时执行mMapView.onDestroy(),实现地图生命周期管理
mMapView.onDestroy();
mLocationClient.stop();
mPoiSearch.destroy();
}
//定位到自身位置
iv_location.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
if (mCurrentLocation != null) {
LatLng latLng = new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude());
MapStatusUpdate mapStatusUpdate = MapStatusUpdateFactory.newLatLng(latLng);
mBaiduMap.animateMapStatus(mapStatusUpdate, 1000);
} }
});
显示我的位置(蓝色圆点)
if (mCurrentLocation == null) {
return;
}
MyLocationData.Builder myLocationDataBuilder = new MyLocationData.Builder();
myLocationDataBuilder.accuracy(mCurrentLocation.getRadius());
myLocationDataBuilder.latitude(mCurrentLocation.getLatitude());
myLocationDataBuilder.longitude(mCurrentLocation.getLongitude());
MyLocationData myLocationData = myLocationDataBuilder.build();
mBaiduMap.setMyLocationEnabled(true);
mBaiduMap.setMyLocationData(myLocationData);
POI检索
第一步,创建POI检索实例
mPoiSearch = PoiSearch.newInstance();
第二步,创建POI检索监听者;
OnGetPoiSearchResultListener poiListener = new OnGetPoiSearchResultListener(){
public void onGetPoiResult(PoiResult result){
//获取POI检索结果
}
public void onGetPoiDetailResult(PoiDetailResult result){
//获取Place详情页检索结果
}
};
第三步,设置POI检索监听者;
mPoiSearch.setOnGetPoiSearchResultListener(poiListener);
第四步,发起检索请求;
mPoiSearch.searchInCity((new PoiCitySearchOption())
.city(“北京”)
.keyword(“美食”)
.pageNum(10));
第五步,释放POI检索实例;
mPoiSearch.destroy();
private OnGetPoiSearchResultListener poiListener = new OnGetPoiSearchResultListener() {
public void onGetPoiResult(PoiResult result) {
// 获取POI检索结果
List<PoiInfo> allPoi = result.getAllPoi();
for (int i = 0; i < allPoi.size(); i++) {
PoiInfo poiInfo = allPoi.get(i);
String tmp = new String();
tmp += "位置:" + poiInfo.address + "\r\n";
tmp += "名称:" + poiInfo.name + "\r\n";
tmp += "电话:" + poiInfo.phoneNum + "\r\n";
Log.d("MainActivity", tmp);
}
mBaiduMap.clear();
PoiOverlay poiOverlay = new PoiOverlay(mBaiduMap);
poiOverlay.setData(result);
poiOverlay.addToMap(); } public void onGetPoiDetailResult(PoiDetailResult result) {
// 获取Place详情页检索结果
}
};
iv_search.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
if (mCurrentLocation == null) {
return;
}
String key = et_key.getText().toString().trim();
if (TextUtils.isEmpty(key)) {
Toast.makeText(MainActivity.this, "输入内容不能为空", Toast.LENGTH_SHORT).show();
return;
}
PoiNearbySearchOption poiNearbySearchOption = new PoiNearbySearchOption();
LatLng latLng = new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude());
poiNearbySearchOption.location(latLng);
poiNearbySearchOption.keyword(key);
poiNearbySearchOption.pageCapacity(100).pageNum(0).radius(10 * 1000).sortType(PoiSortType.distance_from_near_to_far);
mPoiSearch.searchNearby(poiNearbySearchOption); }
});
路线检索
点击Marker,弹出对话框,进行路线检索
InfoWindow infoWindow = new InfoWindow(view, position, -20);相对于原点的偏移位置
mBaiduMap.setOnMarkerClickListener(new OnMarkerClickListener() { @Override
public boolean onMarkerClick(Marker marker) {
mCurrentMarker = marker;
LatLng position = marker.getPosition();
View view = View.inflate(MainActivity.this, R.layout.info_window, null);
ImageView iv_baidu = (ImageView) view.findViewById(R.id.iv_baidu);
ImageView iv_walk = (ImageView) view.findViewById(R.id.iv_walk);
ImageView iv_bus = (ImageView) view.findViewById(R.id.iv_bus);
ImageView iv_car = (ImageView) view.findViewById(R.id.iv_car);
ImageView iv_share = (ImageView) view.findViewById(R.id.iv_share);
iv_baidu.setOnClickListener(MainActivity.this);
iv_walk.setOnClickListener(MainActivity.this);
iv_bus.setOnClickListener(MainActivity.this);
iv_car.setOnClickListener(MainActivity.this);
iv_share.setOnClickListener(MainActivity.this);
InfoWindow infoWindow = new InfoWindow(view, position, -20);
mBaiduMap.showInfoWindow(infoWindow);
return true;
}
});
点击图片选择:步行、公交、自驾等,加载到百度地图
public void onClick(View v) {
if (mCurrentMarker == null) {
return;
}
switch (v.getId()) {
case R.id.iv_baidu:
BaiduMapRoutePlan.setSupportWebRoute(true);
RouteParaOption routeParaOption = new RouteParaOption();
routeParaOption.cityName(mCurrentLocation.getCity());
routeParaOption.startPoint(new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude()));
routeParaOption.endPoint(mCurrentMarker.getPosition());
BaiduMapRoutePlan.openBaiduMapTransitRoute(routeParaOption, this);
break;
case R.id.iv_walk:
WalkingRoutePlanOption walkingRoutePlanOption = new WalkingRoutePlanOption();
PlanNode planNode = PlanNode.withLocation(new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude()));
walkingRoutePlanOption.from(planNode );
PlanNode toPlanNode = PlanNode.withLocation(mCurrentMarker.getPosition());
walkingRoutePlanOption.to(toPlanNode );
mRoutePlanSearch.walkingSearch(walkingRoutePlanOption ); break;
case R.id.iv_bus:
// Tra transitRouteOverlay = new Tr();
TransitRoutePlanOption transitRoutePlanOption = new TransitRoutePlanOption();
transitRoutePlanOption.city(mCurrentLocation.getCity());
PlanNode planNode2 = PlanNode.withLocation(new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude()));
PlanNode toPlanNode2 = PlanNode.withLocation(mCurrentMarker.getPosition());
transitRoutePlanOption.from(planNode2);
transitRoutePlanOption.to(toPlanNode2);
mRoutePlanSearch.transitSearch(transitRoutePlanOption);
break;
case R.id.iv_car:
DrivingRoutePlanOption drivingRoutePlanOption = new DrivingRoutePlanOption();
PlanNode planNode3 = PlanNode.withLocation(new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude()));
PlanNode toPlanNode3 = PlanNode.withLocation(mCurrentMarker.getPosition());
drivingRoutePlanOption.from(planNode3);
drivingRoutePlanOption.to(toPlanNode3);
mRoutePlanSearch.drivingSearch(drivingRoutePlanOption );
break;
case R.id.iv_share:
LocationShareURLOption locationShareURLOption = new LocationShareURLOption();
locationShareURLOption.location(mCurrentMarker.getPosition());
locationShareURLOption.name("分享一个位置");
locationShareURLOption.snippet("来自66的分享");
mShareUrlSearch.requestLocationShareUrl(locationShareURLOption );
break; default:
break;
} }
onClick
如果没有装百度地图
自定义线路检索
private void initView() {
mMapView = (MapView) findViewById(R.id.bmapView);
mBaiduMap = mMapView.getMap();
mSpinner = (Spinner) findViewById(R.id.spinner);
tv_info = (TextView) findViewById(R.id.tv_info);
iv_location = (ImageView) findViewById(R.id.iv_location);
mPoiSearch = PoiSearch.newInstance();
mPoiSearch.setOnGetPoiSearchResultListener(poiListener);
et_key = (EditText) findViewById(R.id.et_key);
iv_search = (ImageView) findViewById(R.id.iv_search);
tv_route = (TextView) findViewById(R.id.tv_route);
mRoutePlanSearch = RoutePlanSearch.newInstance();
mRoutePlanSearch.setOnGetRoutePlanResultListener(listener);
.........
定义监听
private OnGetRoutePlanResultListener listener = new OnGetRoutePlanResultListener() {
public void onGetWalkingRouteResult(WalkingRouteResult result) {
if (walkingRouteOverlay!=null) {
walkingRouteOverlay.removeFromMap();
walkingRouteOverlay = null;
}
if (transitRouteOverlay!=null) {
transitRouteOverlay.removeFromMap();
transitRouteOverlay = null;
}
if (drivingRouteOverlay!=null) {
drivingRouteOverlay.removeFromMap();
drivingRouteOverlay = null;
}
walkingRouteOverlay = new WalkingRouteOverlay(mBaiduMap);
WalkingRouteLine walkingRouteLine = result.getRouteLines().get(0);
int distance = walkingRouteLine.getDistance();
int duration = walkingRouteLine.getDuration();
tv_route.setText(distance+"米"+duration/60+"分钟");
/*TaxiInfo taxiInfo = result.getTaxiInfo();
if (taxiInfo!=null) {
tv_route.setText("约"+taxiInfo.getTotalPrice()+"约"+taxiInfo.getDistance()+"米");
}else {
tv_route.setText("没有找到打的信息");
}*/
walkingRouteOverlay.setData(walkingRouteLine);
walkingRouteOverlay.addToMap();
walkingRouteOverlay.zoomToSpan(); } public void onGetTransitRouteResult(TransitRouteResult result) {
if (walkingRouteOverlay!=null) {
walkingRouteOverlay.removeFromMap();
walkingRouteOverlay = null;
}
if (transitRouteOverlay!=null) {
transitRouteOverlay.removeFromMap();
transitRouteOverlay = null;
}
if (drivingRouteOverlay!=null) {
drivingRouteOverlay.removeFromMap();
drivingRouteOverlay = null;
}
transitRouteOverlay = new TransitRouteOverlay(mBaiduMap);
TransitRouteLine transitRouteLine = result.getRouteLines().get(0);
tv_route.setText(transitRouteLine.getDistance()+"米"+transitRouteLine.getDuration()/60+"分钟");
transitRouteOverlay.setData(transitRouteLine);
transitRouteOverlay.addToMap();
transitRouteOverlay.zoomToSpan();
} public void onGetDrivingRouteResult(DrivingRouteResult result) {
if (walkingRouteOverlay!=null) {
walkingRouteOverlay.removeFromMap();
walkingRouteOverlay = null;
}
if (transitRouteOverlay!=null) {
transitRouteOverlay.removeFromMap();
transitRouteOverlay = null;
}
if (drivingRouteOverlay!=null) {
drivingRouteOverlay.removeFromMap();
drivingRouteOverlay = null;
}
drivingRouteOverlay = new DrivingRouteOverlay(mBaiduMap);
DrivingRouteLine drivingRouteLine = result.getRouteLines().get(0);
tv_route.setText(drivingRouteLine.getDistance()+"米"+drivingRouteLine.getDuration()/60+"分钟");
drivingRouteOverlay.setData(result.getRouteLines().get(0));
drivingRouteOverlay.addToMap();
drivingRouteOverlay.zoomToSpan(); }
};
定义点击事件
public void onClick(View v) {
if (mCurrentMarker == null) {
return;
}
switch (v.getId()) {
case R.id.iv_baidu:
BaiduMapRoutePlan.setSupportWebRoute(true);
RouteParaOption routeParaOption = new RouteParaOption();
routeParaOption.cityName(mCurrentLocation.getCity());
routeParaOption.startPoint(new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude()));
routeParaOption.endPoint(mCurrentMarker.getPosition());
BaiduMapRoutePlan.openBaiduMapTransitRoute(routeParaOption, this);
break;
case R.id.iv_walk:
WalkingRoutePlanOption walkingRoutePlanOption = new WalkingRoutePlanOption();
PlanNode planNode = PlanNode.withLocation(new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude()));
walkingRoutePlanOption.from(planNode );
PlanNode toPlanNode = PlanNode.withLocation(mCurrentMarker.getPosition());
walkingRoutePlanOption.to(toPlanNode );
mRoutePlanSearch.walkingSearch(walkingRoutePlanOption ); break;
case R.id.iv_bus:
// Tra transitRouteOverlay = new Tr();
TransitRoutePlanOption transitRoutePlanOption = new TransitRoutePlanOption();
transitRoutePlanOption.city(mCurrentLocation.getCity());
PlanNode planNode2 = PlanNode.withLocation(new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude()));
PlanNode toPlanNode2 = PlanNode.withLocation(mCurrentMarker.getPosition());
transitRoutePlanOption.from(planNode2);
transitRoutePlanOption.to(toPlanNode2);
mRoutePlanSearch.transitSearch(transitRoutePlanOption);
break;
case R.id.iv_car:
DrivingRoutePlanOption drivingRoutePlanOption = new DrivingRoutePlanOption();
PlanNode planNode3 = PlanNode.withLocation(new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude()));
PlanNode toPlanNode3 = PlanNode.withLocation(mCurrentMarker.getPosition());
drivingRoutePlanOption.from(planNode3);
drivingRoutePlanOption.to(toPlanNode3);
mRoutePlanSearch.drivingSearch(drivingRoutePlanOption );
break;
case R.id.iv_share:
LocationShareURLOption locationShareURLOption = new LocationShareURLOption();
locationShareURLOption.location(mCurrentMarker.getPosition());
locationShareURLOption.name("分享一个位置");
locationShareURLOption.snippet("来自66的分享");
mShareUrlSearch.requestLocationShareUrl(locationShareURLOption );
break; default:
break;
} }
位置分享
短串分享是指,用户搜索查询后得到的每一个地理位置结果将会对应一条短串(短链接),用户可以通过短信、邮件或第三方分享组件(如微博、微信等)把短串分享给其他用户从而实现地理位置信息的分享。当其他用户收到分享的短串后,点击短串即可打开手机上的百度地图客户端或者手机浏览器进行查看。
在INITVIEW初始化
mShareUrlSearch = ShareUrlSearch.newInstance();
mShareUrlSearch.setOnGetShareUrlResultListener(shareUrlResultListener);
定义监听
private OnGetShareUrlResultListener shareUrlResultListener = new OnGetShareUrlResultListener() {
public void onGetPoiDetailShareUrlResult(ShareUrlResult result) {
//分享POI详情
}
public void onGetLocationShareUrlResult(ShareUrlResult result) {
//分享位置信息
//TODO:///
String url = result.getUrl();
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, url);
sendIntent.setType("text/plain");//
startActivity(Intent.createChooser(sendIntent, "调用的系统分享"));
}
};
在点击事件定义
case R.id.iv_share:
LocationShareURLOption locationShareURLOption = new LocationShareURLOption();
locationShareURLOption.location(mCurrentMarker.getPosition());
locationShareURLOption.name("分享一个位置");
locationShareURLOption.snippet("来自66的分享");
mShareUrlSearch.requestLocationShareUrl(locationShareURLOption );
break;
android 开发(百度地图)的更多相关文章
- Android开发百度地图(一)--显示基本地图
最近由于比赛的需要,自己学习了一下百度地图的开发.希望以下的内容能够对大家有用. 一.开发前的准备工作: 1.注册百度账号,并登录.(有百度账号的话直接登录) 2.申请Key,地址:http://de ...
- Android开发-百度地图之电子围栏
功能实现:根据经纬度创建一个坐标,判断该坐标是否在指定圆形覆盖范围内 两个计算方法,直接套用: /** * 地球半径 */private static double EARTH_RADIUS = 63 ...
- Android studio 百度地图开发(3)地图导航
Android studio 百度地图开发(3)地图导航 email:chentravelling@163.com 开发环境:win7 64位,Android Studio,请注意是Android S ...
- Android studio 百度地图开发(2)地图定位
Android studio 百度地图开发(2)地图定位 email:chentravelling@163.com 开发环境:win7 64位,Android Studio,请注意是Android S ...
- Android使用百度地图出现闪退及定位时显示蓝屏问题
目录 1.Android使用百度地图出现闪退 2.Android使用百度地图定位出现蓝屏问题 1.Android使用百度地图出现闪退 一般情况下出现闪退是在AndroidManifest.x ...
- Android studio百度地图demo出现230错误,key校验失败
转自daoxiaomianzi原文 Android studio 百度地图demo出现230错误,key校验失败 使用AndroidStudio导入Baidu地图的as版的demo,引入后,发现没有k ...
- android 基于百度地图api开发定位以及获取详细地址
一:百度地图开发必须要到百度开发平台android开发api下载相应的库,已经申请百度地图开发key. 二:新建项目baidumaplocation.设计main.xml文件这里注意的是MapView ...
- Android学习——百度地图开发定位与显示Demo
百度地图给我们提供了很丰富的API供我们进行二次开发.百度地图的SDK与定位SDK在今年6月份进行了更新. 地图更新为3.0,定位更新为4.2.百度说:这次更新对接口有了较大部分的调整,与之前版本号不 ...
- android的百度地图开发(一)
1,注册百度开发者账号 2,申请key ,注意开发版SH和发布版的SH 获取开发版SHA1: 输入命令:keytool -list -v -keystore debug.keystore,回车输入 ...
- Android 调用百度地图API
一.到 百度地图开发平台下载SDK http://lbsyun.baidu.com/index.php?title=androidsdk/sdkandev-download 1.点击自定义下载 2.下 ...
随机推荐
- mac下安装使用svn
mac自带了svn服务端和客户端,所以只需要简单配置一下就可以使用 转自 http://blog.sina.com.cn/s/blog_677fb16e01011i6l.html 1.创建svn ...
- MFC之常用控件(四)
常用控件主要包括:静态文本框.编辑框.单选按钮.复选框.分组框.列表框.组合框.图片控件.列表控件.树形控件和进度条控件等等.本节教程先来讲解静态文本框的使用. 控件的通知消息 在将静态文本框的使用之 ...
- 最简单的PC机串口通信程序
把串口当作文件IO来操作,简单易行! 已验证,gcc和tcc都可以编译成功,并使用. 需注意,先有串口,改好红色字体串口号再编译运行! #include <stdio.h> #i ...
- 分布式服务框架dubbo原理解析 转
alibaba有好几个分布式框架,主要有:进行远程调用(类似于RMI的这种远程调用)的(dubbo.hsf),jms消息服务(napoli.notify),KV数据库(tair)等.这个框架/工具/产 ...
- <dependency>spring-webmvc</dependency>
Spring 4.2.0.RELEASE版本: <dependency> <groupId>org.springframework</groupId> <ar ...
- java.lang.NoClassDefFoundError: Could not initialize class ......
在测试数据字典工具类的时候一直报这个错误,找了好久,原来是SpringContextUtils这个类没有放入到容器中. 但是我在SpringContextUtils上面加了注解的,为什么注解没有扫到呢 ...
- HTML: 仿写一个财经类静态的网页
要求:仿写一个静态的网页,主要采用HTML+CSS+DIV的布局方式, 新建两个文件:demo.html.demo.css 图片素材:image.zip demo.html代码如下: <!doc ...
- Java基础之处理事件——添加工具栏(Sketcher 7 with File toolbar buttons)
控制台程序. 工具栏在应用程序窗口中通常位于内容面板顶部的菜单栏下,包含直接访问菜单选项的按钮.在Sketcher程序中可以为最常用的菜单项添加工具栏. 工具栏是javax.swing.JToolBa ...
- 《30天自制操作系统》11_day_学习笔记
harib08a: 鼠标的显示问题:我们可以看到,鼠标移到窗口最右侧之后就不能再移动了,而WIN中,鼠标是可以移动到最右边隐藏起来的.怎么办?把鼠标指针显示的范围扩宽就行!我们来修改一下HariMai ...
- 实验十五_安装新的int 9中断例程
安装一个新的int 9中断例程,功能:在DOS下,按下“A”键后,除非不在松开, 如果松开,就显示满屏幕的“A”:其他的键照常处理. 提示:按下一个键时产生的扫描码称为通码,松开一个键产生的扫描 ...