Android笔记:使用百度地图如何得到速度

2022-01-10 15:19:16 浏览数 (1)

该功能需判断你的location是否是从GPS得到的,用location.getLocType() == BDLocation.TypeGpsLocation来判断

代码语言:javascript复制
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){
sb.append("nspeed : ");
sb.append(location.getSpeed());
sb.append("nsatellite : ");
sb.append(location.getSatelliteNumber());
sb.append("ndirection : ");
sb.append("naddr : ");
sb.append(location.getAddrStr());
sb.append(location.getDirection());
} else if (location.getLocType() == BDLocation.TypeNetWorkLocation){
sb.append("naddr : ");
sb.append(location.getAddrStr());
//运营商信息
sb.append("noperationers : ");
sb.append(location.getOperators());
}
logMsg(sb.toString());
Log.i("BaiduLocationApiDem", sb.toString());
}

} 

0 人点赞