Android GPS GPSBasics project hacking

简介: 一、参考源码:   GPS Basic Example - Android Example     http://androidexample.com/GPS_Basic__-__Android_Example/index.

一、参考源码:

  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
        
    }
}

 

目录
相关文章
|
5月前
|
JSON Java 定位技术
【Android App】GPS获取定位经纬度和根据经纬度获取详细地址讲解及实战(附源码和演示 超详细)
【Android App】GPS获取定位经纬度和根据经纬度获取详细地址讲解及实战(附源码和演示 超详细)
285 0
|
5月前
|
XML Java 定位技术
【Android App】定位导航GPS中开启手机定位功能讲解及实战(附源码和演示 超详细)
【Android App】定位导航GPS中开启手机定位功能讲解及实战(附源码和演示 超详细)
120 0
|
Java Shell 定位技术
Android 6.0 默认关闭定位和GPS,开启后默认选省电,永不休眠
Android 6.0 默认关闭定位和GPS,开启后默认选省电,永不休眠
218 0
|
定位技术 Android开发 Windows
|
定位技术 Android开发 网络架构
|
定位技术 Android开发
xamarin android使用gps定位获取经纬度
看了文章你会得出以下几个结论 1.android定位主要有四种方式GPS,Network(wifi定位、基站定位),AGPS定位 2.绝大部分android国产手机使用network进行定位是没有作用的,肯定是无法获取获取位置信息(当然也肯定是有办法解决这种问题的) 3.android 的GPS定位需要一定时间的,大概一分钟左右。
2381 0
|
Android开发 编解码
mokoid android open source HAL hacking in a picture
/************************************************************************** * mokoid android HAL hacking in a picture * 声明: * 之前已经对mokoid开源项目源代码进行跟踪分析,但是总感觉对其中的工作 * 机制运行理解不到位,所以索性这次采用更直观的分析方式,用图来表示她的工 * 做原理,调用机制。
881 0
|
前端开发 Android开发
Android custom View AirConditionerView hacking
package com.example.arc.view; import android.content.Context; import android.graphics.Canvas; import android.
644 0
|
定位技术 Android开发 iOS开发
I.MX6 GPS Android HAL Framework 调试
I.MX6 GPS Android HAL Framework 调试 一、参考文章: android4.3 GPS定位问题 http://blog.
1466 0