权限:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>

布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_dingwei"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.fuxin_zhongji.dingwei">
<TextView
android:id="@+id/tv1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tv2"
android:layout_below="@+id/tv1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>

main:

package com.example.fuxin_zhongji;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView; public class dingwei extends AppCompatActivity {
private LocationManager locationManager;
private TextView tv1;
private TextView tv2; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dingwei);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
initLinter();
initView(); } private void initLinter() {
final LocationListener lo = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
//纬度
double latitude = location.getLatitude();
//经度
double longitude = location.getLongitude();
tv1.setText(String.valueOf(latitude));
tv2.setText(String.valueOf(longitude)); } @Override
public void onStatusChanged(String s, int i, Bundle bundle) { } @Override
public void onProviderEnabled(String s) { } @Override
public void onProviderDisabled(String s) { }
}; if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, lo); } private void initView() {
tv1 = (TextView) findViewById(R.id.tv1);
tv2 = (TextView) findViewById(R.id.tv2);
}
}

andorid简易定位的更多相关文章

  1. Andorid实现点击获取验证码倒计时效果

    这篇文章主要介绍了Andorid实现点击获取验证码倒计时效果,这种效果大家经常遇到,想知道如何实现的,请阅读本文   我们在开发中经常用到倒计时的功能,比如发送验证码后,倒计时60s再进行验证码的获取 ...

  2. 第一章 Andorid系统移植与驱动开发概述 - 读书笔记

    Android驱动月考1 第一章 Andorid系统移植与驱动开发概述 - 读书笔记 1.Android系统的架构: (1)Linux内核,Android是基于Linux内核的操作系统,并且开源,所以 ...

  3. Cordova webapp实战开发:(5)如何写一个Andorid下自动更新的插件?

    在 <Cordova webapp实战开发:(4)Android环境搭建>中我们搭建好了开发环境,也给大家布置了调用插件的预习作业,做得如何了呢?今天我们来学一下如何自己从头建立一个And ...

  4. 第三次个人作业——关于K米(Andorid)的案例分析

    第三次个人作业--关于K米(Andorid)的案例分析 1.K米简介 官方网址:http://www.ktvme.com/ 2.评测 2.1.上手体验 带着找bug的心态,兴致勃勃地开始体验 K米.打 ...

  5. android:id="@id/resid" , andorid:id="@+id/resid" 的区别

    的区别?android:id="@id/resid"    // 引用现有的资源idandorid:id="@+id/resid"  // 新增一个资源id i ...

  6. Andorid手机振动器(Vibrator)的使用

    标签: android vibrator 震动器 it 分类: Andorid 获取振动器Vibrator实例: Vibrator  mVibrator = (Vibrator) context.ge ...

  7. js判断手机端操作系统(Andorid/IOS)

    非常实用的js判断手机端操作系统(Andorid/IOS),并自动跳转相应下载界面 androidURL = "http://xxx/xxx.apk"; var browser = ...

  8. 小牟Andorid下面MD5具体实现的思路总结

    Android的开发往往需要一定数目demo 从今起MD5一些加密算法提取物 看看是如何实现的 首先,我们必须明确为什么加密? 1 数据安全处理 2 防止数据窃取 3 有效的避免恶意攻击 4 保证文件 ...

  9. andorid之摄像头驱动流程--MTK平台

    原文地址:andorid之摄像头驱动流程--MTK平台 作者:守候心田 camera成像原理: 景物通过镜头生产光学图像投射到sensor表面上,然后转为模拟电信号,经过数模变成数字图像信号,在经过D ...

随机推荐

  1. [物理学与PDEs]第3章第1节 等离子体

    1.  磁流体力学研究等离子体这种导电流体在电磁场中的运动. 2.  任何物质由于 $T, p$ 等条件的不同而可以处于固态.液态.气态 (常见的三种聚集态) 或等离子体. 3.  等离子体就是电离气 ...

  2. 二维、三维 Laplace 算子的极坐标表示

    (1) 设 $(r,\theta)$ 是 $\bbR^2$ 的极坐标, 即 $$\bex x=r\cos\theta,\quad y=r\sin \theta. \eex$$ 证明 Laplace 算 ...

  3. Tupper自我指涉公式生成器

  4. Centos7 安装 jdk 1.8

    Centos7 安装 jdk 1.8 1.下载安装包 链接: https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloa ...

  5. 分布式系列七: zookeeper简单用法

    zookeeper是分布式开源框架, 是Google Chubby的一个实现, 主要作为分布式系统的协调服务. Dobbo等框架使用了其功能. zookeeper特性 顺序一致性: 事务请求最终会严格 ...

  6. dubbo服务运行的三种方式

    dubbo服务运行,也就是让生产服务的进程一直启动.如果生产者进程挂掉,也就不存在生产者,消费者不能进行消费. Dubbo服务运行的三种方式如下:1.使用Servlet容器运行(Tomcat.Jett ...

  7. mysql索引与查询优化

    索引加锁 对于InnoDB来说,索引可以让查询锁住更少的行,从而可以在并发情况下拥有更佳表现. 下面演示一下查询锁与索引之间的关系. 前面使用的t_user_action_log表目前有一个id为主键 ...

  8. iOS URL Cache文章推荐 (待完成)

    推荐链接是:http://www.cnblogs.com/Mike-zh/archive/2016/02/24/5210169.html http://blog.csdn.net/y550918116 ...

  9. 第四章:Oracle12c 数据库在linux环境安装

    一:搭建yum 仓库 对于新手可以参考此文:<Vmware Workstation _linux yum 仓库搭建>.<CentOS7.2 创建本地YUM源和局域网YUM源> ...

  10. Google Android SDK开发范例大全笔记 二

    网络设备管理相关相关 代码地址 1 WifiManager LocationManager分别控制 wifi及GPS WifiManager 判断网络状态 ,LocationManager判断定位状态 ...