解决方案 »

  1.   

     
    <service
                android:name="com.baidu.location.f"
                android:enabled="true"
                android:process=":remote" >
     </service>
      

  2.   

    忘记使用格式,再发个public class MainActivity extends Activity { BMapManager mBMapMan;
    MapView mMapView;
    MapController mc; @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    /*
     * mBMapMan = new BMapManager(getApplicationContext());
     * mBMapMan.init(null);
     */
    setContentView(R.layout.activity_main);
    /*
     * mMapView = (MapView) findViewById(R.id.mp); GeoPoint center = new
     * GeoPoint((int) (39.915 * 1E6), (int) (116.404 * 1E6)); mc =
     * mMapView.getController();
     * 
     * mc.setCenter(center); mc.setZoom(12);
     * 
     * mMapView.setBuiltInZoomControls(true);
     * mMapView.setDoubleClickZooming(true); mMapView.setTraffic(true);
     * mMapView.showScaleControl(true); mMapView.refresh();
     */ /**
     * 定义定位端
     */
    // LocationClient locationClient = new
    // LocationClient(MainActivity.this);
    LocationClient locationClient = new LocationClient(
            getApplicationContext());
    locationClient.registerLocationListener(new BDLocationListener() { @Override
    public void onReceiveLocation(BDLocation location) {
    // TODO Auto-generated method stub
    if (location == null) {
    return;
    } StringBuffer sb = new StringBuffer();
    sb.append("time:");
    sb.append(location.getTime());
    sb.append("\n"); sb.append("error type:");
    sb.append(location.getLocType());
    sb.append("\n"); sb.append("latitude : ");
    sb.append(location.getLatitude());
    sb.append("\n"); sb.append("lontitude : ");
    sb.append(location.getLongitude());
    sb.append("\n"); sb.append("radius : ");
    sb.append(location.getRadius());
    sb.append("\n");
    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());
    } mc.animateTo(new GeoPoint((int) (location.getLatitude()),
            (int) (location.getLongitude())));
    logMsg(sb.toString());
    } @Override
    public void onReceivePoi(BDLocation poiLocation) {
    // TODO Auto-generated method stub
    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");
    }
    mc.animateTo(new GeoPoint((int) (poiLocation.getLatitude()),
            (int) (poiLocation.getLongitude())));
    logMsg(sb.toString());
    }
    }); /**
     * 设置定位信息
     */
    LocationClientOption option = new LocationClientOption();
    // 设置定位模式
    // 定位模式(高精度定位模式,低功耗定位模式和仅用设备定位模式),返回坐标类型,是否打开GPS等等。
    option.setLocationMode(LocationMode.Device_Sensors); // 设置发起定位请求的间隔时间为5000ms
    option.setScanSpan(5000); // 返回的定位结果包含地址信息
    option.setIsNeedAddress(true); // 返回的定位结果包含手机机头的方向
    option.setNeedDeviceDirect(true);

    //打开gps  
    option.setOpenGps(true); locationClient.setLocOption(option); locationClient.start();
    boolean ss = locationClient.isStarted();
    /**
     * 发起定位请求
     */
    if (locationClient != null)
    if (locationClient.isStarted()) {
    locationClient.requestLocation();
    } else
    Log.d("LocSDK3", "locClient is null or not started"); } public void logMsg(String string) {
    // TODO Auto-generated method stub
    Log.v("locationClient:", string);
    }
    }
      

  3.   

    locationClient.start(); 并不能马上就定位好。所以你start() 之后,马上判断 .isStarted(),总是返回false。你在.registerLocationListener()里注册的侦听事件中判断 .isStarted(),就能发现这个时候才为true
      

  4.   

    楼上说的也是有一定原因。这个百度地图我前几天也做过定位,就按照api上的做了一下,start()后也没有加等待,isStart()的返回值就已经是true了,而且我也是烂手机上面测试的可以。楼主可以先按照楼上的试试吧