博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java代码实现如何获取当前经纬度?(安卓的话可以用GPS取)
阅读量:6166 次
发布时间:2019-06-21

本文共 2510 字,大约阅读时间需要 8 分钟。

import android.app.Activity;import android.os.Bundle;import android.location.*;import android.content.*;import android.util.Log;import android.widget.TextView;  public class GPSLocationListenActivity extends Activity implements LocationListener {    LocationManager locman;    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);                  locman = (LocationManager)getSystemService(Context.LOCATION_SERVICE);    }          @Override    protected void onResume(){        if (locman != null){            locman.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,0,this);                  }        super.onResume();    }          @Override    protected void onPause(){        if (locman != null){            locman.removeUpdates(this);        }        super.onPause();    }          @Override    public void onLocationChanged(Location location){        TextView textView1 = (TextView)findViewById(R.id.textView1);        textView1.setText("Latitude:Longitude - "        +String.valueOf(location.getLatitude()) +":"+String.valueOf(location.getLongitude()));                  TextView textView2 = (TextView)findViewById(R.id.textView2);        textView2.setText(String.valueOf(location.getTime()));                                    Log.v("----------", "----------");        Log.v("Latitude", String.valueOf(location.getLatitude()));        Log.v("Longitude", String.valueOf(location.getLongitude()));        Log.v("Accuracy", String.valueOf(location.getAccuracy()));        Log.v("Altitude", String.valueOf(location.getAltitude()));        Log.v("Time", String.valueOf(location.getTime()));        Log.v("Speed", String.valueOf(location.getSpeed()));         Log.v("Bearing", String.valueOf(location.getBearing()));    }          @Override    public void onProviderDisabled(String provider){          }          @Override    public void onProviderEnabled(String provider){    }          @Override    public void onStatusChanged(String provider, int status, Bundle extras){        switch(status){        case LocationProvider.AVAILABLE:            Log.v("Status","AVAILABLE");            break;        case LocationProvider.OUT_OF_SERVICE:            Log.v("Status","OUT_OF_SERVICE");            break;        case  LocationProvider.TEMPORARILY_UNAVAILABLE:            Log.v("Status","TEMPORARILY_UNAVAILABLE");            break;                      }    }}

 

转载地址:http://vpuba.baihongyu.com/

你可能感兴趣的文章
Sharepoint学习笔记—修改SharePoint的Timeouts (Execution Timeout)
查看>>
CSS引入的方式有哪些? link和@import的区别?
查看>>
Redis 介绍2——常见基本类型
查看>>
asp.net开发mysql注意事项
查看>>
(转)Cortex-M3 (NXP LPC1788)之EEPROM存储器
查看>>
ubuntu set defult jdk
查看>>
[译]ECMAScript.next:TC39 2012年9月会议总结
查看>>
【Xcode】编辑与调试
查看>>
用tar和split将文件分包压缩
查看>>
[BTS] Could not find stored procedure 'mp_sap_check_tid'
查看>>
PLSQL DBMS_DDL.ALTER_COMPILE
查看>>
Activity生命周期
查看>>
高仿UC浏览器弹出菜单效果
查看>>
Ubuntu忘记密码,进不了系统的解决方法
查看>>
[原创]白盒测试技术思维导图
查看>>
<<Information Store and Management>> 读书笔记 之八
查看>>
Windows 8 开发之设置合约
查看>>
闲说HeartBeat心跳包和TCP协议的KeepAlive机制
查看>>
MoSQL
查看>>
Hibernate多对一外键单向关联(Annotation配置)
查看>>