asasassa

本文介绍了一个Android应用中实现位置更新及发送功能的方法。通过监听GPS位置变化,并使用按钮触发位置信息的更新与发送,实现了对当前地理位置的实时获取与远程分享。文中详细展示了如何初始化UI元素、设置监听器以及捕获并处理异常。
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); updateBtn = (Button) this.findViewById(R.id.update); sendBtn = (Button) this.findViewById(R.id.send); utc = (TextView) this.findViewById(R.id.val_UTC); dataStatus = (TextView) this.findViewById(R.id.val_data_status); currentLatitude = (TextView) this .findViewById(R.id.val_current_latitude); currentLontitude = (TextView) this .findViewById(R.id.val_current_longitude); direction = (TextView) this.findViewById(R.id.val_direction); speed = (TextView) this.findViewById(R.id.val_speed); locationlisterner = new TraceMeLocationListener(this); locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationlisterner); updateBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Location location = locationManager .getLastKnownLocation(LocationManager.GPS_PROVIDER); updateLocationInfo(location); } }); sendBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Location location = locationManager .getLastKnownLocation(LocationManager.GPS_PROVIDER); updateLocationInfo(location); try { sendMyLocation(location); } catch (URISyntaxException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值