android网络-GPS获取定位信息
来源:互联网 发布:长虹32寸网络电视 编辑:程序博客网 时间:2024/05/16 14:39
设置每60秒,每移动十米向LocationProvider获取一次GPS的定位信息
当LocationProvider可用,不可用或定位信息改变时,调用updateView,更新显示
程序效果:按下按钮后,按要求更新定位信息的显示
DDMS的Emulator Control面板中Manual输入经度和纬度值,单击“send”,即可向模拟器发出GPS定位信息(模拟手机中GPS开启状态下自动获取定位信息)
先加上两个权限,第二个为获取定位信息的权限
<uses-permission android:name="android.permission.INTERNET"/><uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
主activity
package com.song;import android.app.Activity;import android.location.Location;import android.location.LocationListener;import android.location.LocationManager;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.TextView;public class C613_Googlemap2Activity extends Activity { /** Called when the activity is first created. */Button button;TextView textview;LocationManager manager;Location location; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); textview=(TextView)findViewById(R.id.textview); button=(Button)findViewById(R.id.button); manager=(LocationManager)getSystemService(LOCATION_SERVICE); //从GPS_PROVIDER获取最近的定位信息 location=manager.getLastKnownLocation(LocationManager.GPS_PROVIDER); updateView(location); //判断GPS是否可用 System.out.println("state="+manager.isProviderEnabled(LocationManager.GPS_PROVIDER)); button.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stub//设置每60秒,每移动十米向LocationProvider获取一次GPS的定位信息//当LocationProvider可用,不可用或定位信息改变时,调用updateView,更新显示manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 10, new LocationListener() {@Overridepublic void onStatusChanged(String provider, int status, Bundle extras) {// TODO Auto-generated method stub}@Overridepublic void onProviderEnabled(String provider) {// TODO Auto-generated method stub//updateView(manager.getLastKnownLocation(provider));}@Overridepublic void onProviderDisabled(String provider) {// TODO Auto-generated method stubupdateView(null);}@Overridepublic void onLocationChanged(Location location) {// TODO Auto-generated method stub//location为变化完的新位置,更新显示updateView(location);}});}}); } //更新显示内容的方法 public void updateView(Location location) { StringBuffer buffer=new StringBuffer(); if(location==null) { textview.setText("未获得服务"); return; } buffer.append("经度:"+location.getLongitude()+"\n"); buffer.append("纬度:"+location.getLatitude()+"\n"); buffer.append("高度:"+location.getAltitude()+"\n"); buffer.append("速度:"+location.getSpeed()+"\n"); buffer.append("方向:"+location.getBearing()+"\n"); textview.setText(buffer.toString()); }}显示效果
- android网络-GPS获取定位信息
- Android 获取GPS和网络定位信息
- Android获取位置信息 - GPS定位 Network定位
- Android-GPS,网络定位
- android 获取GPS定位,
- 使用GPS获取定位信息
- Unity3d,获取GPS定位信息
- Android中使用GPS和NetWork获取定位信息
- Android中使用GPS和NetWork获取定位信息
- Android获取当前位置(GPS和网络定位)
- Android获取当前位置(GPS和网络定位)
- Android获取GPS定位数据
- Android GPS定位 获取经纬度
- Android GPS定位获取当前位置
- Android GPS定位 获取经纬度
- Android GPS定位 获取经纬度
- android之GPS或网络获取经纬度信息
- 使用j2me获取gps定位信息
- MYSQL数据库基础
- 数学之美系列二十:自然语言处理的教父 马库斯
- HTTP Status 404 - No result defined for action com.lnzkx.action.PeronAction and result success
- 数学之美系列二十一:布隆过滤器(Bloom Filter)
- utf8_bin跟utf8_general_ci的区别
- android网络-GPS获取定位信息
- 数学之美系列二十二:由电视剧《暗算》所想到的 — 谈谈密码学的数学原理
- Android Asynchronous HTTPClient的实现和优化
- mount/umount 16问
- objective-c for Java程序员 第一部分2
- Struts功能详解——Action
- ITK求两图像局部均方差
- GDUT2012-1002最小差值
- 数学之美系列 二十三 输入一个汉字需要敲多少个键 — 谈谈香农第一定律