一、参考源码:

  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. Python中被双下划线包围的魔法方法

    基本的魔法方法 __new__(cls[, ...]) 用来创建对象 1. __new__ 是在一个对象实例化的时候所调用的第一个方法 2. 它的第一个参数是这个类,其他的参数是用来直接传递给 __i ...

  2. python面向对象编程基础

    演示了 Python 类与对象的编程基础, 包括属性.方法.继承.组合.动态创建类. python 版本: 2.7.5 class SimpleClass(object): ''' a simple ...

  3. Linux学习笔记之Linux启动级别

    对于绝大多数Linux程序员来说,进入Linux系统后一般看到的是黑乎乎的界面(开发模式),因为系统如果启动选择开发模式,会减少启动时间,优化内存等.但是通常我们刚安装完Linux系统,然后进去以后是 ...

  4. 微信小程序:页面配置 page.json

    微信小程序:页面配置 page.json 一.页面配置 page.json 如果整个小程序的风格是蓝色调,那么可以在 app.json 里边声明顶部颜色是蓝色即可. 实际情况可能不是这样,可能你小程序 ...

  5. 20155201 2016-2017-2 《Java程序设计》第三周学习总结

    20155201 2016-2017-2 <Java程序设计>第三周学习总结 教材学习内容总结 - 第四章要点: 4.1类与对象 类定义时使用class关键词,基本模式为 class na ...

  6. Windows10系统远程桌面连接出现卡顿如何解决

    最新的windows10系统下,用户只要开启远程桌面连接,就能够轻松地操控其他电脑.但是,最近部分用户在win10中启用远程连接时,发现电脑窗口变得非常缓慢卡顿,这是怎么回事呢?其实,该问题与系统的设 ...

  7. RC 522模块在LINUX平台调试笔记

    硬件平台: 1 主控:SMDK Exynos4412 POP S5M8767A 2 RFID模块:君盾集团提供的RC522模块 3 通信接口:SPI 软件平台:Android ICS & ke ...

  8. 【bzoj2721】[Violet 5]樱花

    题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=2721 好久没做数学题了,感觉有些思想僵化,走火入魔了. 这道题就是求方程$ \frac ...

  9. RabbitMQ入门_01_简介与安装

    A. 资源与参考文档 官网:https://www.rabbitmq.com/ B. 学习目的 部门目前使用其他部门维护的 WebLogic 的 JMS 消息服务,缺乏足够的技术支持与运维支持.随着基 ...

  10. bzoj2049: [Sdoi2008]Cave 洞穴勘测 lct裸题

    题意:三种操作一种摧毁一条边,一种链接一条边,一种查询两个点是否联通 题解:lct的link和cut即可 /********************************************** ...