80,337
社区成员
发帖
与我相关
我的任务
分享
private void init() {
if (aMap == null) {
aMap = mapView.getMap();
mUiSettings = aMap.getUiSettings();
//显示比例尺
mUiSettings.setScaleControlsEnabled(true);
aMap.setLocationSource(this);// 设置定位监听
aMap.getUiSettings().setMyLocationButtonEnabled(true);// 设置默认定位按钮是否显示
aMap.setMyLocationEnabled(true);// 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false
}
}
public void onLocationChanged(AMapLocation amapLocation) {
if (mListener != null && amapLocation != null) {
if (amapLocation != null
&& amapLocation.getErrorCode() == 0) {
mListener.onLocationChanged(amapLocation);// 显示系统小蓝点
//新的定位点
newLatLng = new LatLng(amapLocation.getLatitude(),amapLocation.getLongitude());
//绘制新的轨迹
if (lastLatLng != null){
aMap.addPolyline(new PolylineOptions().color(Color.rgb(0, 153, 255))
.add(lastLatLng,newLatLng));
}
lastLatLng = newLatLng;//记录为旧记录点
} else {
String errText = "定位失败," + amapLocation.getErrorCode()+ ": " + amapLocation.getErrorInfo();
Log.e("AmapErr", errText);
}
}
}