无信号  
<service android:name="com.baidu.location.f" android:enabled="true" android:process=":remote" 
    android:permission="android.permission.BAIDU_LOCATION_SERVICE">
    <intent-filter>
        <action android:name="com.baidu.location.service_v2.4"></action>
    </intent-filter>
</service>

以上是版本区别部分。

<permission android:name="android.permission.BAIDU_LOCATION_SERVICE"></permission>
<uses-permission android:name="android.permission.BAIDU_LOCATION_SERVICE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"></uses-permission>
<uses-permission android:name="android.permission.READ_LOGS"></uses-permission>

以上是权限部分

然后就是demo的java部分

package com.xmb.baiduloctest2;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
public class MainActivity extends Activity {
    public LocationClient mLocationClient = null;
    public BDLocationListener myListener = new MyLocationListenner();
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mLocationClient = new LocationClient(this);     //声明LocationClient类
        
        LocationClientOption option = new LocationClientOption();
        option.setOpenGps(true);
        option.setAddrType("detail");
        option.setCoorType("bd09ll");
        option.setScanSpan(5000);
        option.disableCache(true);//禁止启用缓存定位
        option.setPoiNumber(5); //最多返回POI个数 
        option.setPoiDistance(1000); //poi查询距离  
        option.setPoiExtraInfo(true); //是否需要POI的电话和地址等详细信息  
        mLocationClient.setLocOption(option);
        
        mLocationClient.registerLocationListener( myListener );    //注册监听函数
        mLocationClient.start();
        
    }
    
    @Override
       public void onDestroy() {
        mLocationClient.stop();
           super.onDestroy();
       }

    /**
     * 监听函数,又新位置的时候,格式化成字符串,输出到屏幕中
     */
    public class MyLocationListenner implements BDLocationListener {
        @Override
        public void onReceiveLocation(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());
            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("\n省:");
                sb.append(location.getProvince());
                sb.append("\n市:");
                sb.append(location.getCity());
                sb.append("\n区/县:");
                sb.append(location.getDistrict());
                sb.append("\naddr : ");
                sb.append(location.getAddrStr());
            }
            sb.append("\nsdk version : ");
            sb.append(mLocationClient.getVersion());
            sb.append("\nisCellChangeFlag : ");
            sb.append(location.isCellChangeFlag());
            Log.i("out","onReceiveLocation="+sb.toString());
        }
        
        public void onReceivePoi(BDLocation poiLocation) {
            if (poiLocation == null){
                return ; 
            }
            StringBuffer sb = new StringBuffer(256);
            sb.append("Poi time : ");
            sb.append(poiLocation.getTime());
            sb.append("\nerror code : "); 
            sb.append(poiLocation.getLocType());
            sb.append("\nlatitude : ");
            sb.append(poiLocation.getLatitude());
            sb.append("\nlontitude : ");
            sb.append(poiLocation.getLongitude());
            sb.append("\nradius : ");
            sb.append(poiLocation.getRadius());
            if (poiLocation.getLocType() == BDLocation.TypeNetWorkLocation){
                sb.append("\naddr : ");
                sb.append(poiLocation.getAddrStr());
            } 
            if(poiLocation.hasPoi()){
                sb.append("\nPoi:");
                sb.append(poiLocation.getPoi());
            }else{                
                sb.append("noPoi information");
            }
            Log.i("out","onReceivePoi="+sb.toString());
        }
    }
}

 

posted on 2013-04-03 14:18  BenXian  阅读(740)  评论(0编辑  收藏  举报