由于谷歌被天朝封杀所以谷歌地图定位不能用
建议使用百度地图
设置AndroidManifest.xml
在application标签中声明service组件,每个app拥有自己单独的定位service
声明使用权限
private void initLocation(){
mLocationClient = new LocationClient(this,getLocationClientOption());
mLocationClient.registerLocationListener(mLocationListener);
mLocationClient.start();
}
private LocationClientOption getLocationClientOption() {
LocationClientOption option = new LocationClientOption();
option.setOpenGps(true);
option.setAddrType("all");
option.setServiceName(this.getPackageName());
option.setScanSpan(0);
option.disableCache(true);
return option;
}
private BDLocationListener mLocationListener = new BDLocationListener() {
@Override
public void onReceivePoi(BDLocation arg0) {
// do nothing
}
@Override
public void onReceiveLocation(BDLocation location) {
// mActionBar.setProgressBarVisibility(View.GONE);
if(location!=null){
Log.d("tab", "baidu,getLongitude:"+location.getLongitude());
Log.d("tab", "baidu,getLatitude:"+location.getLatitude());
Log.d("tab", "baidu,getAddrStr:"+location.getLocType());
myApplication.address = location;
if(myApplication.address!=null){
mLocationClient.stop();
}
};
}
};
百度地图定位SDK错误码error code 162解决办法以及定位SDKjava.lang.noclassdeffounderror
private void initLocation(){
mLocationClient = new LocationClient(this,getLocationClientOption());
mLocationClient.registerLocationListener(mLocationListener);
mLocationClient.start();
}
private LocationClientOption getLocationClientOption() {
LocationClientOption option = new LocationClientOption();
option.setOpenGps(true);
option.setAddrType("all");
option.setServiceName(this.getPackageName());
option.setScanSpan(0);
option.disableCache(true);
return option;
}
private BDLocationListener mLocationListener = new BDLocationListener() {
@Override
public void onReceivePoi(BDLocation arg0) {
// do nothing
}
@Override
public void onReceiveLocation(BDLocation location) {
// mActionBar.setProgressBarVisibility(View.GONE);
if(location!=null){
Log.d("tab", "baidu,getLongitude:"+location.getLongitude());
Log.d("tab", "baidu,getLatitude:"+location.getLatitude());
Log.d("tab", "baidu,getAddrStr:"+location.getLocType());
myApplication.address = location;
if(myApplication.address!=null){
mLocationClient.stop();
}
};
}
};