一、参考源码:

  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的更多相关文章

  1. Android Mokoid Open Source Project hacking

    /***************************************************************************** * Android Mokoid Open ...

  2. Android GPS应用开发

    转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/5715879.html GPS定位系统由三部分组成,即由GPS卫星组成的空间部分,若干地面组成的控制部分和普通 ...

  3. 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 ...

  4. Android custom View AirConditionerView hacking

    package com.example.arc.view; import android.content.Context; import android.graphics.Canvas; import ...

  5. Android development tools line_endings hacking

    /******************************************************************** * Android development tools li ...

  6. android gps开发必备资料(含测试demo下载)

    入门资料参考: How accurate is Android GPS? Part 1: Understanding Location Data How accurate is Android GPS ...

  7. Android studio 项目(Project)依赖(非Module)

    Android studio 项目(Project)依赖(非Module) 0. 前言 对于Module 级别的依赖大家都知道,今天说下Android Studio下的项目依赖. 场景: A Proj ...

  8. AM335x Android eMMC mkmmc-android.sh hacking

    # AM335x Android eMMC mkmmc-android.sh hacking # # . 有空解读一下android的分区文件. # . 代码来源:https://github.com ...

  9. Android 4.2 project导入 5.0 SDK Eclipse 开发环境出现的问题总结

    Android 4.2 project导入 5.0 SDK Eclipse 开发环境出现的问题总结 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循&qu ...

随机推荐

  1. http之请求报文request

    https://blog.csdn.net/blueheart20/article/details/45174399 户端发送一个HTTP请求到服务器的请求消息包括以下格式: 请求行(request ...

  2. HDU 1879 继续畅通工程(Prim||Kruscal模板题)

    原题链接 Prim(点归并) //异或运算:相同为假,不同为真 #include<cstdio> #include<algorithm> #define maxn 105 us ...

  3. c++第十八天

    p105~p108: 1.迭代器与数组的不同:迭代器的索引值必须是无符号类型,数组的索引无此要求. 2.使用数组的时候编译器一般会把它转化为指针. 3.auto ia2(数组名);的结果是:获得一个指 ...

  4. validform校验框架不显示错误提示

    今天做前端的校验,发现validform这个框架在项目中有,于是就网上搜索一下,开始使用,网上说,嗯,只写一句代码就可以用啦 $("#itemForm").Validform(); ...

  5. Windows Server 2008 R2 web服务器发布在线系统时遇到的问题

    1  HTTP 错误 404.2 - Not Found,由于 Web  服务器上的“ISAPI 和 CGI 限制”列表设置,无法提供您请求的页面(如下图) 打开 Internet 信息服务(IIS) ...

  6. 20145302张薇 《网络对抗技术》逆向及BOF基础实践

    20145302张薇 <网络对抗技术>逆向及BOF基础实践 实验内容 实践对象:名为20145302的linux可执行文件. 该程序正常执行流程是:main调用foo函数,foo函数会简单 ...

  7. 20155201 第十一周Java课堂实践

    一.表达式后缀表达式: a b x c d e / - f x + 二.mini dc MyDC.java import java.util.StringTokenizer; import java. ...

  8. 微信小程序路过——新手不要错过哦!

    应该算是入门篇, 从我怎么0基础然后沿着什么方向走,遇到的什么坑,如何方向解决,不过本人接触不是很多,所以也就了解有限. 小程序的前提: 1.小程序大小不允许超过2M.(也就是本地图片,大图精图不要在 ...

  9. HDU 4745 Two Rabbits(最长回文子序列)

    http://acm.hdu.edu.cn/showproblem.php?pid=4745 题意: 有一个环,现在有两只兔子各从一个点开始起跳,一个沿顺时针,另一个沿逆时针,只能在一圈之内跳,并且每 ...

  10. supervisor进程管理工具

    Supervisor 一个python写的进程管理工具,用来启动.关闭.重启进程,可以同时控制多个进程. 安装: pip install supervisor 配置: 通过配置文件来满足自己的需求 配 ...