一、参考源码:

  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. hdu 5017

    好恶心的题 #include <cstdio> #include <string.h> #include <algorithm> #include <cmat ...

  2. 892. Surface Area of 3D Shapes

    问题 NxN个格子中,用1x1x1的立方体堆叠,grid[i][j]表示坐标格上堆叠的立方体个数,求这个3D多边形的表面积. Input: [[1,2],[3,4]] Output: 34 思路 只要 ...

  3. React 根据 state 修改className

    className={ this.state.isLike ? 'active iconfont icon-xihuan' : 'iconfont icon-xihuan1' }

  4. Cooperation.GTST团队项目总结

    Cooperation.GTST团队项目总结 项目实现情况 目前对于基本UI界面的设计已经实现,对博客园接口XML的解析也已经完成,但是还暂时无法动态获取对应数据. 几张静态预览图展示(侧滑栏设计加入 ...

  5. 关于Drupal中使用hook_schema建立数据库报错PDOException: SQLSTATE[42000]的解决办法

    报错信息如下:PDOException: SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too l ...

  6. myeclipse删除项目后重新导入

    今天安装了myeclipse2017版,刚开始导入项目后然后删除了,发现再次导入进来的时候不可以了. 解决方法:点击file -- >switch workspace -- >other ...

  7. ZOJ 2747 Paint the Wall(离散化+暴力)题解

    题意:给你一个面,然后涂颜色,问你最后剩多少颜色,每种颜色面积. 思路:第一反应是二维线段树,代码又臭又长,可以做.但是这题暴力+离散化就可以过.可以看到他给的n只有100,也就是说最坏情况下会涂10 ...

  8. .Net频繁访问数据库的优化探究(一)

    知识点:DataTable.Linq.lamda表达式.Cache 场景:查询部门的所有员工和管理员,并分配相应的权限 实现过程一般为:查询部门,遍历部门(查询员工.分配权限.查询管理员.分配权限) ...

  9. SQL优化:清理生产环境中已失效字段基本步骤

    1.统计相应字段的数据情况(如:几年没更新,无数据等情况) 2.确认产品逻辑已无效(产品经理邮件确认) 3.数据备份 4.将数据清空(置为0或空) 5.测试环境中删除引用页面 6.修改定时程序,存储过 ...

  10. python有木有哪些必须要学习的高级模块

    python有木有哪些必须要学习的高级模块 字母表