package com.jqyd.android.module.lbs; import android.content.Context; import android.content.Intent; import android.os.Looper; import android.util.Log; import com.jqyd.android.module.lbs.Interface.ILocation; import com.jqyd.android.module.lbs.Interface.ILocationListener; import com.jqyd.android.module.lbs.bean.GeocodeInfo; import com.jqyd.android.module.lbs.bean.LocationInfo; import com.jqyd.android.module.lbs.bean.LocationTimerTask; import com.jqyd.android.module.lbs.util.Optsharepre_interface; /** * @author jinglinxiao * */ public final class LocationClient implements ILocation{ private Context context; private Optsharepre_interface share; public LocationClient(Context context){ this.context = context; share = new Optsharepre_interface(context); } /* (non-Javadoc) * @see com.jqyd.api.Interface.ILocation#request(com.jqyd.api.Interface.ILocationListener) */ @Override public void request(ILocationListener result) { new Baidu_location(context, result); } /* (non-Javadoc) * @see com.jqyd.api.Interface.ILocation#request(int, com.jqyd.api.Interface.ILocationListener) */ @Override public void request(final int locationWay, final ILocationListener resultListener) { new Thread(){ @Override public void run() { Looper.prepare(); new LocationUtils(context).getLocData(locationWay, resultListener); Looper.loop(); } }.start(); } /* (non-Javadoc) * @see com.jqyd.api.Interface.ILocation#getLastKnowLocation() */ @Override public LocationInfo getLastKnowLocation() { LocationInfo info = null; if(share.getDataFromPres("lon") != null&&share.getDataFromPres("lon").equals("")){ info = new LocationInfo(); info.setResultCode(0); info.setLon(Double.parseDouble(share.getDataFromPres("lon"))); info.setLat(Double.parseDouble(share.getDataFromPres("lat"))); info.setAltitude(Double.parseDouble(share.getDataFromPres("altitude"))); info.setSuccess(Integer.parseInt(share.getDataFromPres("success"))); info.setTime(Long.parseLong(share.getDataFromPres("time"))); info.setRadius(Float.parseFloat(share.getDataFromPres("radius"))); info.setErrorcode(Integer.parseInt(share.getDataFromPres("errorcode"))); info.setPosour(Integer.parseInt(share.getDataFromPres("posour"))); info.setGpsStatus(Integer.parseInt(share.getDataFromPres("gpsStatus"))); info.setWlanStatus(Integer.parseInt(share.getDataFromPres("wlanStatus"))); info.setMobileNetworkStatus(Integer.parseInt(share.getDataFromPres("mobileNetworkStatus"))); GeocodeInfo geo = new GeocodeInfo(); if(info.getPosour()==1){ geo.setProvince(share.getDataFromPres("province")); geo.setCity(share.getDataFromPres("city")); geo.setCode(share.getDataFromPres("code")); geo.setCountry(share.getDataFromPres("country")); geo.setPoi(share.getDataFromPres("poi")); geo.setContent(share.getDataFromPres("content")); geo.setCross(share.getDataFromPres("xCross")); geo.setXmlStr(share.getDataFromPres("xmlStr")); geo.setStr1(share.getDataFromPres("str1")); } info.setGisInfo(geo); } return info; } /* (non-Javadoc) * @see com.jqyd.api.Interface.ILocation#regTimerTask(com.jqyd.api.bean.LocationTimerTask, java.lang.Class) */ @Override public boolean regTimerTask(LocationTimerTask task,Class<? extends LocationService> handlerService) { Log.e("xiao","regTimerTask"+handlerService.getName()); Intent intent = new Intent(context,handlerService); intent.putExtra("task", task); context.startService(intent); return true; } /* (non-Javadoc) * @see com.jqyd.api.Interface.ILocation#deleteTimerTask(java.lang.Class) */ @Override public boolean deleteTimerTask(Class<? extends LocationService> handlerService) { Intent intent = new Intent(context,handlerService); context.stopService(intent); return false; } }