一、参考源码:

  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. Selenium IDE的一些操作

    1.运行速度过快时,可能出现找不到元素的情况,影响运行结果,将速度调慢慢一些,就可以运行成功. 如果为其他情况找不到元素,则需要另外找原因,有可能元素定位有问题,有可能无该元素. 2.导出录制的脚本为 ...

  2. Web Services 简介

    通过使用 Web Services,您的应用程序可以向全世界发布信息,或提供某项功能.Web Services 脚本平台需支持 XML + HTTP. Web Services 简介 Web Serv ...

  3. R语言编程

    R中的帮助文档非常有用,其中有四种类型的帮助 help(functionname) 对已经加载包所含的函数显示其帮助文档,用?号也是一样的. help.search('keyword') 对已经安装的 ...

  4. android中代码操作外部SD卡出错:W/System.err(1595): Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)

    AndroidManifest.xml 中加上: <uses-permission android:name="android.permission.WRITE_EXTERNAL_ST ...

  5. Entity Framework 并发处理(转)

    什么是并发? 并发分悲观并发和乐观并发. 悲观并发:比如有两个用户A,B,同时登录系统修改一个文档,如果A先进入修改,则系统会把该文档锁住,B就没办法打开了,只有等A修改完,完全退出的时候B才能进入修 ...

  6. STM32 IO口双向问题

    源: STM32 IO口双向问题

  7. Mysql在InnoDB引擎下索引失效行级锁变表锁案例

    先做好准备,创建InnoDB引擎数据表,并添加了相应的索引 DROP TABLE IF EXISTS `innodb_lock`; CREATE TABLE `innodb_lock` ( `a` ) ...

  8. 20145221 《Java程序设计》第八周学习总结

    20145221 <Java程序设计>第八周学习总结 教材学习内容总结 第十五章部分 - 通用API 通用API 日志: 日志对信息安全意义重大,审计.取证.入侵检测等都会用到日志信息 日 ...

  9. ubuntu16.04安装tensorflow官方教程与机器学习资料【学习笔记】

    tensorflow官网有官方的安装教程:https://www.tensorflow.org/install/install_linux google的机器学习官方快速入门教程:https://de ...

  10. 从头到尾测地理解KMP算法【转】

    本文转载自:http://blog.csdn.net/v_july_v/article/details/7041827 1. 引言 本KMP原文最初写于2年多前的2011年12月,因当时初次接触KMP ...