android studio 加载百度定位

  |   0 评论   |   1,520 浏览

    用Eclipse开发百度定位的时候不报错,可以正常定位,可是当我们迁移到android studio 时却定位不了,为啥呢?

    看代码:

    设置位置信息:

    注册:

    private class MyLocationListener implements BDLocationListener {
    		private int requestCount;// 当前访问了第几次 
    		public MyLocationListener() {
    			requestCount = 0;
    		} 
    		@Override
    		public void onReceiveLocation(BDLocation bdLocation) {     
    			Log.i("aaaaaaaaaaaaaaa", "requestCount==" + requestCount); 
    			Constant.locationInfo.setCity(bdLocation.getCity());// 市 
    			StringBuffer sb = new StringBuffer(256);
    			//sb.append("time : ");
    			//sb.append(bdLocation.getTime());
    			sb.append("error code : ");
    			//error code ==162 加libs里armeabi包的.so 文件
    			sb.append(bdLocation.getLocType());
    		//	sb.append("latitude : ");
    		//	sb.append(bdLocation.getLatitude());
    		//	sb.append("lontitude : ");
    		//	sb.append(bdLocation.getLongitude());
    		//	sb.append("radius : ");
    		//	sb.append(bdLocation.getRadius());
    			if (bdLocation.getLocType() == BDLocation.TypeGpsLocation){
    				//sb.append("speed : ");
    			//	sb.append(bdLocation.getSpeed());
    			//	sb.append("satellite : ");
    			//	sb.append(bdLocation.getSatelliteNumber());
    			//	sb.append("direction : ");
    			//	sb.append("addr : ");
    			//	sb.append(bdLocation.getAddrStr());
    			//	sb.append(bdLocation.getDirection());
    			} else if (bdLocation.getLocType() == BDLocation.TypeNetWorkLocation){
    			//	sb.append("addr : ");
    				//sb.append(bdLocation.getAddrStr());
    				//运营商信息
    				//sb.append("operationers : ");
    				//sb.append(bdLocation.getOperators());
    			}
    			Log.i("aaaaaaaa","error code :=== "+ sb.toString());
    			if (bdLocation != null && Constant.locationInfo.getCity() != null) {
    				String AddrStr = bdLocation.getAddrStr();// 整条地址信息
    				Constant.locationInfo.setProvince(bdLocation.getProvince());// 省
    				Constant.locationInfo.setStreet(bdLocation.getStreet());// 街
    				Constant.locationInfo.setDistrict(bdLocation.getDistrict());// 区
    				// 经度
    				Constant.locationInfo.setLoitude(String.valueOf(bdLocation.getLongitude()));
    				// 纬度
    				Constant.locationInfo.setLatitude(String.valueOf(bdLocation.getLatitude()));
    				Log.i("aaaaaaaaaaaaaaa", Constant.locationInfo.getStreet() + "+Location - +" + AddrStr + "Province=="
    						+ Constant.locationInfo.getProvince() + "City===" + Constant.locationInfo.getCity());
    				Constant.adpager.getSurrounding_loderror_tv().setVisibility(View.GONE);
    				Constant.adpager.getActivitt_top_address_tv().setText(Constant.locationInfo.getStreet());
    				locationClient.stop();
    				params.put("rovince", Constant.locationInfo.getProvince());// 省份
    				params.put("city", Constant.locationInfo.getCity());// 传入市
    				params.put("area", Constant.locationInfo.getDistrict());// 传入区
    				params.put("loitude", Constant.locationInfo.getLoitude());
    				params.put("latitude", Constant.locationInfo.getLatitude());
    				index++;
    				params.put("index", String.valueOf(index));
    				getMerchant(params); //
    			} else {
    				if (requestCount == 10) {
    					Log.i("aaaaaaaaaaaaaaa", "==定位失败");
    					ToastUtils.show(context, "定位失败", 1000);
    					locationClient.stop();
    					// 定位时间太长后,关闭对话框
    					dialog.stopProgressDialog(dialog);
    					Constant.adpager.getSurrounding_loderror_tv().setVisibility(View.VISIBLE);
    					Constant.adpager.getTab1_lv().onRefreshComplete();
    				} else if (!NetUtils.isConnected(context)) {
    					ToastUtils.show(context, "网络链接失败!请检查你的网络", 1000);
    					Constant.adpager.getSurrounding_loderror_tv().setVisibility(View.VISIBLE);
    					Constant.adpager.getTab1_lv().onRefreshComplete();
    					locationClient.stop();
    					return;
    				}
    				dialog.stopProgressDialog(dialog);// 清除dialog
    				requestCount++;
    			}
    			
    		} 
    	}
    清单文件配置:

     

    关于添加权限自己百度:

    好了,看看build.gradle文件:


    好了,这样迁移项目就不会定位报错误码:162



    >