• 百度定位信息存储

    package com.example.testlocation; import java.io.IOException; import java.util.ArrayList; import java.util.List; import com.baidu.location.BDLocation; import com.baidu.location.BDLocationListener; import com.baidu.location.LocationClient; import com.baidu.location.LocationClientOption; import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.util.Log; public class BaiduLocationService extends Service{ //用来保存定位的信息 // private List<fasdfafa> dataList = new ArrayList<E>(); private Locationss locationss; private List<String> list; public void onCreate() { super.onCreate(); list = new ArrayList<String>(); System.out.println("YYY"); Initialatize(); } // 初始化 public void Initialatize() { locationss = new Locationss(); //百度定位服务 LocationClient locationClient; locationClient=new LocationClient(getApplicationContext()); LocationClientOption option=new LocationClientOption(); option.setOpenGps(true); option.setCoorType("bd09ll");//返回的定位结果是百度经纬度,默认值gcj02 option.setScanSpan(1000*10); //当不设此项,或者所设的整数值小于1000(ms)时,采用一次定位模式。 locationClient.setLocOption(option); locationClient.registerLocationListener(locationListener); //设置监听 locationClient.start(); locationClient.requestLocation(); } //百度定位监听器(回调函数) private BDLocationListener locationListener=new BDLocationListener() { @Override public void onReceiveLocation(BDLocation arg0) { Dispose(arg0); } @Override public void onReceivePoi(BDLocation arg0) { Dispose(arg0); } private void Dispose(BDLocation location) { if(location==null) return; StringBuffer sb = new StringBuffer(256); sb.append("time : "); sb.append(location.getTime()); sb.append("\nerror code : "); sb.append(location.getLocType()); sb.append("\nlatitude : "); sb.append(location.getLatitude()); sb.append("\nlontitude : "); sb.append(location.getLongitude()); sb.append("\nradius : "); sb.append(location.getRadius()); locationss.setTime(location.getTime()); locationss.setLatitude(location.getLatitude()+""); locationss.setLontitude(location.getLongitude()+""); String ss = location.getTime()+"|"+location.getLatitude()+"|"+location.getLongitude(); list.add(ss); try { CacheUtil.cacheList(getApplicationContext(), list, "LocationList"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (location.getLocType() == BDLocation.TypeGpsLocation){ sb.append("\nspeed : "); sb.append(location.getSpeed()); sb.append("\nsatellite : "); sb.append(location.getSatelliteNumber()); } else if (location.getLocType() == BDLocation.TypeNetWorkLocation) { sb.append("\naddr : "); sb.append(location.getAddrStr()); } //poiLocation if(location.hasPoi()){ sb.append("\nPoi:"); sb.append(location.getPoi()); }else{ sb.append("\nnoPoi information"); } Log.e("定位结果:",sb.toString()); } }; @Override public IBinder onBind(Intent arg0) { // TODO Auto-generated method stub return null; } }

    0
    202
    1.55MB
    2014-06-25
    9
关注 私信
上传资源赚积分or赚钱