首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

【so easy~】 GPS的那一星半点事儿~

2012-07-19 
【so easy~】 GPS的那点儿事儿~!http://androiddada.iteye.com/最近发现微信等应用都有找附近的人 的新功能。

【so easy~】 GPS的那点儿事儿~!

http://androiddada.iteye.com/

最近发现微信等应用都有找附近的人 的新功能。

遍开始想看看gps

?

于是找了些网上的代码,自己试了试:

?

?

public class GPS_testActivity extends Activity {/** Called when the activity is first created. */   private LinearLayout mainView=null;      private TextView infoView=null;      private TextView locationView=null;            private LocationManager locationManager=null;      private LocationListener locationListener=null;  @Overridepublic void onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState);          mainView=new LinearLayout(this);          mainView.setOrientation(LinearLayout.VERTICAL);          infoView=new TextView(this);          mainView.addView(infoView);          locationView=new TextView(this);          mainView.addView(locationView);          setContentView(mainView);          locationManager_init();  }   /*locationManager初始化*/      void locationManager_init(){          locationManager =(LocationManager)this.getSystemService(GPS_testActivity.LOCATION_SERVICE);          locationListener_init();          locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1000,0, locationListener);      }      /*locatonListener初始化*/      void locationListener_init(){                  locationListener=new LocationListener(){              //位置变化时触发               public void onLocationChanged(Location location) {              System.out.println("onLocationChanged");            locationView.setText("时间:"+location.getTime()+"\n");              locationView.append("经度:"+location.getLongitude()+"\n");              locationView.append("纬度:"+location.getLatitude()+"\n");              locationView.append("海拔:"+location.getAltitude()+"\n");              }              //gps禁用时触发               public void onProviderDisabled(String provider) {              System.out.println("onProviderDisabled");            Toast.makeText(GPS_testActivity.this, "请开启GPS!", Toast.LENGTH_SHORT).show();        Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);        startActivityForResult(intent, 0); // 此为设置完成后返回到获取界面            }              //gps开启时触发               public void onProviderEnabled(String provider) {              Toast.makeText(GPS_testActivity.this, "GPS正常", Toast.LENGTH_SHORT).show();            }              //gps状态变化时触发               public void onStatusChanged(String provider, int status,Bundle extras) {              System.out.println("onStatusChanged");                if(status==LocationProvider.AVAILABLE){                  infoView.setText("当前GPS状态:可见的\n");                  }else if(status==LocationProvider.OUT_OF_SERVICE){                  infoView.setText("当前GPS状态:服务区外\n");                  }else if(status==LocationProvider.TEMPORARILY_UNAVAILABLE){                  infoView.setText("当前GPS状态:暂停服务\n");                  }              }          };      }      }

?布局很简单几个textView显示而已,就不上了

?

客户端得到gps数据传给服务处理。。最后显示出服务返回的数据 搞定!用户看起来很神奇的功能,在代码里并不复杂。

不过服务器端处理数据稍微麻烦写,需要根据经纬度找出你附近的人儿~

http://androiddada.iteye.com/

好了,希望对朋友们有用~

热点排行