mirror of
https://github.com/ZCShou/GoGoGo.git
synced 2026-06-05 21:00:50 +08:00
改进了百度地图请求位置
This commit is contained in:
parent
57d95a1720
commit
cc1c246629
Binary file not shown.
@ -154,17 +154,14 @@ public class MainActivity extends BaseActivity
|
||||
Toolbar toolbar = findViewById(id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
XLog.d("xlog test");
|
||||
|
||||
//sqlite相关
|
||||
initStoreHistory();
|
||||
|
||||
DrawerLayout drawer = findViewById(id.drawer_layout);
|
||||
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
||||
this, drawer, toolbar, string.navigation_drawer_open, string.navigation_drawer_close);
|
||||
drawer.addDrawerListener(toggle);
|
||||
toggle.syncState();
|
||||
|
||||
//sqlite相关
|
||||
initStoreHistory();
|
||||
|
||||
//http init
|
||||
mRequestQueue = Volley.newRequestQueue(this);
|
||||
@ -526,29 +523,67 @@ public class MainActivity extends BaseActivity
|
||||
.longitude(bdLocation.getLongitude()).build();
|
||||
mBaiduMap.setMyLocationData(locData);
|
||||
|
||||
if (isFirstLoc) {
|
||||
isFirstLoc = false;
|
||||
// 这里记录百度地图返回的位置
|
||||
mCurLatLngMap = new LatLng(bdLocation.getLatitude(), bdLocation.getLongitude());
|
||||
MapStatus.Builder builder = new MapStatus.Builder();
|
||||
builder.target(mCurLatLngMap).zoom(18.0f);
|
||||
mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
|
||||
/* 如果出现错误,则需要重新请求位置 */
|
||||
int err = bdLocation.getLocType();
|
||||
if (err == BDLocation.TypeCriteriaException || err == BDLocation.TypeNetWorkException) {
|
||||
mLocClient.requestLocation(); /* 请求位置 */
|
||||
} else {
|
||||
if (isFirstLoc) {
|
||||
isFirstLoc = false;
|
||||
// 这里记录百度地图返回的位置
|
||||
mCurLatLngMap = new LatLng(bdLocation.getLatitude(), bdLocation.getLongitude());
|
||||
MapStatus.Builder builder = new MapStatus.Builder();
|
||||
builder.target(mCurLatLngMap).zoom(18.0f);
|
||||
mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
|
||||
|
||||
XLog.d("First Baidu LatLng: " + mCurLatLngMap);
|
||||
XLog.d("First Baidu LatLng: " + mCurLatLngMap);
|
||||
|
||||
// 这里将百度地图位置转换为 GPS 坐标。实际使用GPS 返回的坐标会更好点
|
||||
double[] latLng = MapUtils.bd2wgs(mCurLatLngMap.longitude, mCurLatLngMap.latitude);
|
||||
mCurLng = latLng[0];
|
||||
mCurLat = latLng[1];
|
||||
XLog.d("First LatLng: " + mCurLng + " " + mCurLat);
|
||||
// 这里将百度地图位置转换为 GPS 坐标。实际使用GPS 返回的坐标会更好点
|
||||
double[] latLng = MapUtils.bd2wgs(mCurLatLngMap.longitude, mCurLatLngMap.latitude);
|
||||
mCurLng = latLng[0];
|
||||
mCurLat = latLng[1];
|
||||
XLog.d("First LatLng: " + mCurLng + " " + mCurLat);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 错误的状态码
|
||||
* <a>http://lbsyun.baidu.com/index.php?title=android-locsdk/guide/addition-func/error-code</a>
|
||||
* <p>
|
||||
* 回调定位诊断信息,开发者可以根据相关信息解决定位遇到的一些问题
|
||||
*
|
||||
* @param locType 当前定位类型
|
||||
* @param diagnosticType 诊断类型(1~9)
|
||||
* @param diagnosticMessage 具体的诊断信息释义
|
||||
*/
|
||||
public void onLocDiagnosticMessage(int locType, int diagnosticType, String diagnosticMessage) {
|
||||
XLog.d("Baidu ERROR: " + locType + "-" + diagnosticType + "-" + diagnosticMessage);
|
||||
}
|
||||
});
|
||||
LocationClientOption option = new LocationClientOption();
|
||||
option.setIsNeedAddress(true);
|
||||
option.setOpenGps(true); // 打开gps
|
||||
option.setCoorType("bd09ll"); // 设置坐标类型
|
||||
option.setScanSpan(1000);
|
||||
//可选,设置是否使用gps,默认false
|
||||
//使用高精度和仅用设备两种定位模式的,参数必须设置为true
|
||||
option.setOpenGps(true);
|
||||
//可选,设置返回经纬度坐标类型,默认GCJ02
|
||||
//GCJ02:国测局坐标;
|
||||
//BD09ll:百度经纬度坐标;
|
||||
//BD09:百度墨卡托坐标;
|
||||
//海外地区定位,无需设置坐标类型,统一返回WGS84类型坐标
|
||||
option.setCoorType("bd09ll");
|
||||
//可选,设置发起定位请求的间隔,int类型,单位ms
|
||||
//如果设置为0,则代表单次定位,即仅定位一次,默认为0
|
||||
//如果设置非0,需设置1000ms以上才有效
|
||||
option.setScanSpan(1200);
|
||||
//可选,设置是否收集Crash信息,默认收集,即参数为false
|
||||
option.SetIgnoreCacheException(true);
|
||||
//可选,设置定位模式,默认高精度
|
||||
//LocationMode.Hight_Accuracy:高精度;
|
||||
//LocationMode. Battery_Saving:低功耗;
|
||||
//LocationMode. Device_Sensors:仅使用设备;
|
||||
option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); //高精度模式
|
||||
//可选,设置是否当GPS有效时按照1S/1次频率输出GPS结果,默认false
|
||||
// option.setLocationNotify(true);
|
||||
mLocClient.setLocOption(option);
|
||||
mLocClient.start();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user