本人从事安卓开发不久,所以写的东西没什么技术含量。
现在写一些我在开发中遇到的问题吧!
关于华为手机无法定位的一些细节问题:
public EUExLocation(Context context, EBrowserView inParent) { super(context, inParent); this.context = context; locationClient = new AMapLocationClient(context); locationOption = new AMapLocationClientOption(); init(); } private void init() { // 设置定位模式为高精度模式 locationOption.setLocationMode(AMapLocationMode.Hight_Accuracy); // 设置定位监听 locationClient.setLocationListener(mLocationListener); // 设置是否需要显示地址信息 locationOption.setOnceLocation(false); locationOption.setNeedAddress(true); /** * 设置是否优先返回GPS定位结果,如果30秒内GPS没有返回定位结果则进行网络定位 注意:只有在高精度模式下的单次定位有效,其他方式无效 */ locationOption.setGpsFirst(false); // 设置是否开启缓存 locationOption.setLocationCacheEnable(true); // 设置发送定位请求的时间间隔,最小值为1000,如果小于1000,按照1000算 locationOption.setInterval(2000); } private AMapLocationListener mLocationListener = new AMapLocationListener() { @Override public void onLocationChanged(AMapLocation location) { String strs = location.toString(); String data = new Gson().toJson(strs); Log.i(TAG, "*****" + data); jsCallback("uexLocation.cbGetLocation", 0, 0, data); } };原来的代码是String data = new Gson().toJson(location);,因为华为的一些手机使用Gson.toJson无法直接解析一个AMapLocation对象,所以需要将此对象转为字符串,再使用Gson.toJson(xxx)解析。以上方法解决了我的问题,希望能帮到您!
