Location location=locationManager.getLastKonwLocation(provider); i find that location==null; through my G4 i can find my location but int System 1.5 i find nothing,who can tell me why?
this is code : public void onCreate() { super.onCreate(); //PengPengShare.tv.setText("呵呵"); init(); } /* public void onStart(Intent intent,int startId) { super.onStart(intent, startId); //init(); PengPengShare.tv.setText("呵呵"); }*/ private final LocationListener locationListener=new LocationListener() { @Override public void onLocationChanged(Location location) { // TODO Auto-generated method stub upadateWithNewLocation(location); } @Override public void onProviderDisabled(String provider) { // TODO Auto-generated method stub upadateWithNewLocation(null); } @Override public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } @Override public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } }; private void init() { // TODO Auto-generated method stub /*这里要插入一段自动打开GPS的代码 boolean gpsEnabled = Settings.Secure.isLocationProviderEnabled( getContentResolver(), LocationManager.GPS_PROVIDER ); if(gpsEnabled) { //关闭GPS Settings.Secure.setLocationProviderEnabled( getContentResolver(), LocationManager.GPS_PROVIDER, false ); } else { //打开GPS Settings.Secure.setLocationProviderEnabled( getContentResolver(), LocationManager.GPS_PROVIDER, true); }*/ locManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE); criteria=new Criteria(); criteria.setAccuracy(0); //一下四行每个啥子意思我还没弄清楚 /* criteria.setAccuracy(Criteria.ACCURACY_FINE);// 设置为最大精度 criteria.setAltitudeRequired(false);//不要求海拔信息 criteria.setBearingRequired(false);// 不要求方位信息 criteria.setCostAllowed(true);//是否允许付费 criteria.setPowerRequirement(Criteria.POWER_LOW);// 对电量的要 求 //将gps和基站都打开 /*Settings.Secure.putString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "network"); Settings.Secure.putString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "gps");*/ criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(false); criteria.setPowerRequirement(Criteria.POWER_LOW); provider=locManager.getBestProvider(criteria, true); location=locManager.getLastKnownLocation(provider); //三分钟更新一次地理位置并发送 if(location==null) { //upadateWithNewLocation(location); locManager.requestLocationUpdates(provider, 10, 10, locationListener); //locationManager.removeUpdates(locationListener);当蓝牙蓝牙连上后就不再更新地理位 置 }} private void upadateWithNewLocation(Location location2) { // TODO Auto-generated method stub if(location!=null) { jingDu=location.getLongitude(); weidu=location.getLatitude(); PengPengShare.tv.setText(jingDu+""); PengPengShare.tv2.setText(weidu+""); //-1的意思就是不重复 //每刷新一次获得的地理位置,再通过Socket传送到服务器端,那么这里还需要有个传送的接口 /*SendLocation send=new SendLocation(); //注意这里,不需要使用线程,因为只有再再次获得的时候才再次建立socket连接发送数据 send.sendJingduLocation(jingDu); send.sendWeiduLocation(weidu);*/ } else { PengPengShare.tv.setText("hha"); //isGetLocation=false;//没有取得地理位置 //AlertDialog ad=new AlertDialog.Builder(context).setIcon(R.drawable.icon).setTitle("没有获取地理位 置") //.setPositiveButton("OK",null).setMessage("没有获取位置信 息").create(); //ad.show(); Log.i("ssss","sssss"); } } public void onDestroy() { super.onDestroy(); //locManager.addGpsStatusListener(listener); } } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en