ANDROID_MARS学习笔记_S03_003_LocationManager、LocationListener
一、简介

二、代码
1.xml
(1)AndroidManifest.xml
增加
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
</manifest>
2.java
(1)MainActivity.java
package com.location1; import android.app.Activity;
import android.content.Context;
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; public class MainActivity extends Activity { private Button button = null;
private LocationManager locationManager = null;
LocationListener locationListener = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); button = (Button)findViewById(R.id.buttonId);
locationManager = (LocationManager) MainActivity.this.getSystemService(Context.LOCATION_SERVICE); locationListener = new LocationListener() {
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
System.out.println("onStatusChanged--->");
} @Override
public void onProviderEnabled(String provider) {
System.out.println("onProviderEnabled--->");
} @Override
public void onProviderDisabled(String provider) {
System.out.println("onProviderDisabled--->");
} @Override
public void onLocationChanged(Location location) {
System.out.println("onLocationChanged--->");
System.out.println(location.getLatitude());
System.out.println(location.getLongitude());
}
}; button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//绑定监听器,第二个参数表示更新的最小时间(毫秒);第三个参数表示更新的最小距离(米)
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
}
});
}
}
ANDROID_MARS学习笔记_S03_003_LocationManager、LocationListener的更多相关文章
- ANDROID_MARS学习笔记_S03_004_getAllProviders、LOCATIONLISTENER、getBestProvider
一.代码 1.xml(1)activity_main.xml <uses-permission android:name="android.permission.ACCESS_FINE ...
- ANDROID_MARS学习笔记_S01_012_RatingBar
1.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns: ...
- ANDROID_MARS学习笔记_S01_012_SeekBar
1.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns: ...
- ANDROID_MARS学习笔记_S01_011ProgressBar
文档是这样来设置样式 <ProgressBar android:layout_width="wrap_content" android:layout_height=" ...
- ANDROID_MARS学习笔记_S01_010日期时间控件
1.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns: ...
- ANDROID_MARS学习笔记_S01_009Relative_LAYOUT例子
1. <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android ...
- ANDROID_MARS学习笔记_S01_008Linear_layout例子
1.netstone_layout.xml <?xml version="1.0" encoding="utf-8"?> <LinearLay ...
- ANDROID_MARS学习笔记_S01_007Linear_layout嵌套与layout_weight的设置
一.介绍 二.1.linear_layout.xml <?xml version="1.0" encoding="utf-8"?> <Line ...
- ANDROID_MARS学习笔记_S01_006ImageView
一.ImageView介绍 设置scalType Must be one of the following constant values. Constant Value Description ma ...
随机推荐
- SMTP ERROR: Password command failed: 535 Incorrect authentication data
在处理一个使用PHPMailer来发送电邮,我在本地使用我的163邮箱来做测试发送电邮,能够成功的发送电邮:当上传到正式平台时,出现了,类似这样的错误信息 SMTP ERROR: Password c ...
- 用 SQL 计算时间差值
;WITH res1 AS ( SELECT * FROM ( SELECT ROW_NUMBER() OVER (PARTITION BY F2 ORDER BY F1) AS rn,F1,F2 F ...
- leetcode处女作
闲来无事[真的吗?你确定→_→ 在leetcode上刷了一道题.费时一小时,也是醉了.谨以此文,纪念我的伟大成果.[呵呵 题目是找出非排序数组中缺少的最小正整数.要求时间复杂度O(n),空间复杂度为常 ...
- 时间处理总结(二)oracle
不断总结中................. 1.等于land.djsj=to_date('2016/7/26','yyyy-MM-dd')2.大于等于land.djsj>=to_date('2 ...
- HUD加载动画支持gif
下载地址 https://pan.baidu.com/s/1c2E7QW4
- editActionsForRowAtIndexPath(iOS8) tableview编辑(删除、插入、移动)
ios8 出来的左滑小菜单 可以自定义想要的按钮 (要求ios8以上) - (nullable NSArray<UITableViewRowAction *> *)tableView:(U ...
- P1396 营救
P1396 营救 218 通过 571 提交 题目提供者yeszy 标签 二分 图论 并查集 福建省历届夏令营 难度 普及- 题目描述 "咚咚咚--""查水表!" ...
- linux相关解压命令
ZIP 我们可以使用下列的命令压缩一个目录: # zip -r archive_name.zip directory_to_compress 下面是如果解压一个zip文档: # unzip archi ...
- 提高C#编程水平不可不读的50个要诀
提高C#编程水平的50个要点 1.总是用属性 (Property) 来代替可访问的数据成员 2.在 readonly 和 const 之间,优先使用 readonly 3.在 as 和 强制类型转换之 ...
- Redis的PHP操作手册(自用)
String 类型操作 string是redis最基本的类型,而且string类型是二进制安全的.意思是redis的string可以包含任何数据.比如jpg图片或者序列化的对象 $redis-> ...