Android GPS GPSBasics project hacking
一、参考源码:
GPS Basic Example - Android Example
http://androidexample.com/GPS_Basic__-__Android_Example/index.php?view=article_discription&aid=68&aaid=93
二、Permission:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
三、Example:
package com.example.gpsbasics; import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import android.app.Activity;
import android.content.Context; public class MainActivity extends Activity implements LocationListener { private LocationManager locationManager; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/********** get Gps location service LocationManager object ***********/
/********** 获取GPS服务管理对象 ************/
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); /*
Parameters :
First(provider) : the name of the provider with which to register
: 注册的名字
Second(minTime) : the minimum time interval for notifications, in milliseconds. This field is only used as a hint to conserve power, and actual time between location updates may be greater or lesser than this value.
: 最小通知时间间隔,以毫秒为单位。此字段仅作为节省电力方式,并且位置更新之间的实际时间可以比该值更大或更小。
Third(minDistance) : the minimum distance interval for notifications, in meters
: 最小间隔通知,以毫秒为单位
Fourth(listener) : a {#link LocationListener} whose onLocationChanged(Location) method will be called for each location update
: 每个位置更新时谁的onLocationChanged (位置)方法将被调用
*/ locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
3000, // 3 sec
10, this); /********* After registration onLocationChanged method called periodically after each 3 sec ***********/
} /************* Called after each 3 sec **********/
@Override
public void onLocationChanged(Location location) { // location.getLatitude(): 纬度
// location.getLongitude(): 维度
String str = "Latitude: "+location.getLatitude()+" \nLongitude: "+location.getLongitude();
Toast.makeText(getBaseContext(), str, Toast.LENGTH_LONG).show();
Log.e("GPSBasics", "onLocationChanged.");
} @Override
public void onProviderDisabled(String provider) { /******** Called when User off Gps *********/ Toast.makeText(getBaseContext(), "Gps turned off ", Toast.LENGTH_LONG).show();
} @Override
public void onProviderEnabled(String provider) { /******** Called when User on Gps *********/ Toast.makeText(getBaseContext(), "Gps turned on ", Toast.LENGTH_LONG).show();
} @Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub }
}
Android GPS GPSBasics project hacking的更多相关文章
- Android Mokoid Open Source Project hacking
/***************************************************************************** * Android Mokoid Open ...
- Android GPS应用开发
转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/5715879.html GPS定位系统由三部分组成,即由GPS卫星组成的空间部分,若干地面组成的控制部分和普通 ...
- Android requires compiler compliance level 5.0 or 6.0. Found '1.8' instead. Please use Android Tools>Fix project Properties.
重装操作系统之后,或者破坏了Android的开发环境之后,需要重新配置好Android的开发环境.但是配置好后,导入原有的项目时,报错: Android requires compiler compl ...
- Android custom View AirConditionerView hacking
package com.example.arc.view; import android.content.Context; import android.graphics.Canvas; import ...
- Android development tools line_endings hacking
/******************************************************************** * Android development tools li ...
- android gps开发必备资料(含测试demo下载)
入门资料参考: How accurate is Android GPS? Part 1: Understanding Location Data How accurate is Android GPS ...
- Android studio 项目(Project)依赖(非Module)
Android studio 项目(Project)依赖(非Module) 0. 前言 对于Module 级别的依赖大家都知道,今天说下Android Studio下的项目依赖. 场景: A Proj ...
- AM335x Android eMMC mkmmc-android.sh hacking
# AM335x Android eMMC mkmmc-android.sh hacking # # . 有空解读一下android的分区文件. # . 代码来源:https://github.com ...
- Android 4.2 project导入 5.0 SDK Eclipse 开发环境出现的问题总结
Android 4.2 project导入 5.0 SDK Eclipse 开发环境出现的问题总结 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循&qu ...
随机推荐
- leetcode 数据库题解
184. Department Highest Salary 题意: The Employee table holds all employees. Every employee has an Id, ...
- JDBC连接数据库(一)
原文地址http://www.cnblogs.com/hongten/archive/2011/03/29/1998311.html JDBC连接数据库 创建一个以JDBC连接数据库的程序,包含7个步 ...
- 1:3访问 servlet API 的两种方式(request,session等内置对象)
1:解耦方式 2:耦合方式: ========================================== ========================================== ...
- F题:等差区间(RMQ||线段树)
原题大意:原题链接 题解链接 给定一个长为n的数组元素和q次区间[l,r]询问,判断区间[l,r]内元素排序后能否构成等差数列 #include<cmath> #include<c ...
- 11月26号host
127.0.0.1 localhost255.255.255.255 broadcasthost::1 localhostfe80::1%lo0 localhost # Google start216 ...
- python连接mysql,redis类方法
#coding:utf8 import pymysql import redis import conf '''MYSQL DB Object''' class Mysql(): def __init ...
- python webdriver 测试框架-数据驱动DDT的例子
先在cmd环境 运行 pip install ddt 安装数据驱动ddt模块 脚本: #encoding=utf-8 from selenium import webdriver import un ...
- Block作为参数时的使用
Block作为参数使用,常见于各框架之中,比如在封装一个类时,当做什么事情由外界去决定,什么时候调用由自己的类决定时,这时候就需要将block作为参数使用. 下面我们模仿AFNetworking的ma ...
- JS文档DOM
访问指定节点 通过document节点获取 document.getElementById(elementId) document.getElementsByName(elementName) d ...
- HDU 1556 Color the ball(线段树:区间更新)
http://acm.hdu.edu.cn/showproblem.php?pid=1556 题意: N个气球,每次[a,b]之间的气球涂一次色,统计每个气球涂色的次数. 思路: 这道题目用树状数组和 ...