通过Location获取Address的使用!

Android高手进阶教程(十五)之---通过Location获取Address的使用! 大家好,上一节我讲了一下如何通过LocationManager来获取Location,没有看过上一节的同学,可以点击如下链接返回查看:Android高手进阶教程十四之---Android Location的使用!我们获取Location的目的之一肯定是有获取这个位置的详细地址,而我们有了Location在来获取Address就相对简单多了,因为GoogleApi已经封装好了方法,我们只需呀通过Location获取GeoPoint,然后在通过GeoPoint来获取我们想要的Address.下面是我做的一个简单 阅读详情


转自:http://blog.csdn.net/android_tutor/article/details/5692517

大家好,上一节我讲了一下如何通过LocationManager来获取Location,没有看过上一节的同学,可以点击如下链接返回查看:

Android高手进阶教程十四之---Android Location的使用!

我们获取Location的目的之一肯定是有获取这个位置的详细地址,而我们有了Location在来获取Address就相对简单多了,因为GoogleApi已经封装好了方法,我们只需呀通过Location获取GeoPoint,然后在通过GeoPoint来获取我们想要的Address.下面是我做的一个简单的Demo.

 

第一步新建一个Android工程LocationDemo,注意这里选用的是(Google APIs),下面是文件目录结构:

 

第二步: 修改main.xml(相比第十四节增加了一个address的TextView),代码如下:

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     >  
  7. <TextView   
  8.     android:id="@+id/longitude"   
  9.     android:layout_width="fill_parent"   
  10.     android:layout_height="wrap_content"   
  11.     android:text="longitude:"  
  12.     />  
  13. <TextView  
  14.     android:id="@+id/latitude"    
  15.     android:layout_width="fill_parent"   
  16.     android:layout_height="wrap_content"   
  17.     android:text="latitude:"  
  18.     />  
  19. <TextView  
  20.     android:id="@+id/address"    
  21.     android:layout_width="fill_parent"   
  22.     android:layout_height="wrap_content"   
  23.     />  
  24. </LinearLayout>  

第三步:修改LocationDemo.java(增加了两个方法)代码如下:

  1. package com.android.tutor;  
  2. import java.util.List;  
  3. import java.util.Locale;  
  4. import com.google.android.maps.GeoPoint;  
  5. import android.app.Activity;  
  6. import android.content.Context;  
  7. import android.location.Address;  
  8. import android.location.Geocoder;  
  9. import android.location.Location;  
  10. import android.location.LocationManager;  
  11. import android.os.Bundle;  
  12. import android.widget.TextView;  
  13. public class LocationDemo extends Activity {  
  14.      
  15.     private TextView longitude;  
  16.     private TextView latitude;  
  17.     private TextView address;  
  18.     @Override  
  19.     public void onCreate(Bundle savedInstanceState) {  
  20.         super.onCreate(savedInstanceState);  
  21.         setContentView(R.layout.main);  
  22.           
  23.         longitude = (TextView)findViewById(R.id.longitude);  
  24.         latitude = (TextView)findViewById(R.id.latitude);  
  25.         address = (TextView)findViewById(R.id.address);  
  26.           
  27.         Location mLocation = getLocation(this);  
  28.         GeoPoint gp = getGeoByLocation(mLocation);  
  29.         Address mAddress = getAddressbyGeoPoint(this, gp);  
  30.       
  31.           
  32.           
  33.         longitude.setText("Longitude: " + mLocation.getLongitude());  
  34.         latitude.setText("Latitude: " + mLocation.getLatitude());  
  35.         address.setText("Address: " + mAddress.getCountryName()+"," + mAddress.getLocality());  
  36.     }  
  37.       
  38.     //Get the Location by GPS or WIFI  
  39.     public Location getLocation(Context context) {  
  40.         LocationManager locMan = (LocationManager) context  
  41.                 .getSystemService(Context.LOCATION_SERVICE);  
  42.         Location location = locMan  
  43.                 .getLastKnownLocation(LocationManager.GPS_PROVIDER);  
  44.         if (location == null) {  
  45.             location = locMan  
  46.                     .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);  
  47.         }  
  48.         return location;  
  49.     }  
  50.     //通过Location获取GeoPoint  
  51.      public  GeoPoint getGeoByLocation(Location location) {  
  52.          GeoPoint gp = null;  
  53.          try {  
  54.              if (location != null) {  
  55.                  double geoLatitude = location.getLatitude() * 1E6;  
  56.                  double geoLongitude = location.getLongitude() * 1E6;  
  57.                  gp = new GeoPoint((int) geoLatitude, (int) geoLongitude);  
  58.              }  
  59.          } catch (Exception e) {  
  60.              e.printStackTrace();  
  61.          }  
  62.          return gp;  
  63.      }  
  64.      //通过GeoPoint来获取Address  
  65.      public  Address getAddressbyGeoPoint(Context cntext, GeoPoint gp) {  
  66.          Address result = null;  
  67.          try {  
  68.              if (gp != null) {  
  69.                  Geocoder gc = new Geocoder(cntext, Locale.CHINA);  
  70.                   
  71.                  double geoLatitude = (int) gp.getLatitudeE6() / 1E6;  
  72.                  double geoLongitude = (int) gp.getLongitudeE6() / 1E6;  
  73.                    
  74.                  List<Address> lstAddress = gc.getFromLocation(geoLatitude,  
  75.                          geoLongitude, 1);  
  76.                  if (lstAddress.size() > 0) {  
  77.                      result = lstAddress.get(0);  
  78.                  }  
  79.              }  
  80.          } catch (Exception e) {  
  81.              e.printStackTrace();  
  82.          }  
  83.          return result;  
  84.      }  
  85. }  

第四步:最重要一步在AndroidManiefest.xml中导入Google Api(第14行代码)库,代码如下:

[xhtml] view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  3.       package="com.android.tutor"  
  4.       android:versionCode="1"  
  5.       android:versionName="1.0">  
  6.     <application android:icon="@drawable/icon" android:label="@string/app_name">  
  7.         <activity android:name=".LocationDemo"  
  8.                   android:label="@string/app_name">  
  9.             <intent-filter>  
  10.                 <action android:name="android.intent.action.MAIN" />  
  11.                 <category android:name="android.intent.category.LAUNCHER" />  
  12.             </intent-filter>  
  13.         </activity>  
  14.         <uses-library android:name="com.google.android.maps" />   
  15.     </application>  
  16.     <uses-sdk android:minSdkVersion="7" />  
  17.     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>  
  18. </manifest>   

 

第五步:运行上述工程,效果如下图如示:


Android开发—通过Location获取Address Android开发—通过Location获取Address,获取手机一些信息 立即下载

相关推荐

SiC双向车载充电器技术解析与V2G应用

碳化硅(SiC)功率器件凭借其高击穿电场强度、优异热导率和低开关损耗特性,正在重塑电力电子系统的设计边界。作为第三代半导体材料的代表,SiC MOSFET通过降低80%的开关损耗,使车载充电器(OBC)效率突破96.5%。在双向能量转换架构中,图腾柱PFC与CLLC谐振变换器的组合实现了ZVS软开关,配合三维集成散热方案使功率密度达54W/in³。这些技术进步直接支撑了V2G(车辆到电网)应用场景,使电动车成为虚拟电厂(VPP)的关键单元。通过智能充放电策略优化,电池循环寿命可提升至4000次以上,为电力市

weixin_30693683的博客 283

Android高手进阶教程(十四)---通过Location获取Address的使用!

大家好,上一节我讲了一下如何通过LocationManager来获取Location,没有看过上一节的同学,可以点击如下链接返回查看: Android高手进阶教程(十三)---Android Location的使用! 我们获取Location的目的之一肯定是有获取这个位置的详

Peter_hucq的专栏 959

小样本学习概述

目录 前言 小样本学习存在的意义? 什么是小样本学习? 小样本学习的方法有哪些? 结语 前言 小样本学习(Few-Shot Learning)是近几年兴起的一个研究领域,小样本学习旨在解决在数据有限的机器学习任务。 小样本学习存在的意义? 近些年,以深度卷积神经网络为代表的深度学习方法在各类机器学习任务上取得了优异的成绩——很多任务上已经超越了人类表现。狂欢背后,危机四伏。因为这些深度学习方法work的关键之一是海量标注数据的支持。 但是在工业界,很多时候难以获得海量的训练数据,更.

DwD-的博客 3万+

Android根据经纬度获取位置信息

Android内部是支持这个操作的,不需要借助任何的第三方工具 主要就是Geocoder这个类。   下面是工具类全部代码。 import android.content.Context; import android.location.Address; import android.location.Geocoder; import android.util.Log; import a...

yang_niuxxx的博客 7402

STM32+OpenCV云台PID调参实战:从震荡到丝滑跟踪的进阶之路

本文详细介绍了基于STM32和OpenCV的跟踪云台PID调参实战经验。从硬件搭建、PID控制原理到调参技巧,系统讲解了如何通过调整比例、积分和微分参数解决系统震荡问题,实现从震荡到丝滑跟踪的进阶过程,特别适合电赛和嵌入式视觉控制开发者参考。

tgb3456789的博客 721

UCIe物理层 —— 逻辑协议 (2)

本章开始主要介绍UCIe协议第四章,物理层逻辑定义和规范。如其他的通信协议一样,接口的物理层包含两个部分,逻辑子层和电气子层。其中逻辑层主要负责:1.定义接口信号和时序2. 定义发送端如何将上层数据分发到各个物理通道以及接收端如何把从各个通道收到的数据恢复成byte stream(Flit)。3. Broken Lane的repair和remap。4. 链路初始化,训练(training)和电源状态管理/切换。5. 扰码Scrambling和training sequence的产生。

m0_47581558的博客 1489

根据经纬度获取城市名

这是我自己的笔记,如有侵犯到您请留言联系 private void initGecooder() { Geocoder gc = new Geocoder(this, Locale.getDefault()); List locationList = null; try { locationList = gc.getFromLocation(strlat, strlon, 1); }

xiaxiao_new的博客 3841

通达信强龙趋势幅图指标 - 精准捕捉趋势,把握强势行情,多角度分析个股,强弱一目了然

STICKLINE(趋势>0 AND SJTJ,4.8,5.8,1.5,0),COLORYELLOW;STICKLINE(资金>0 AND SJTJ,1.2,2.2,1.5,0),COLOR0080FF;STICKLINE(异动>0 AND SJTJ,0,1,1.5,0),COLORFF0080;STICKLINE(异动=0 AND SJTJ,0,1,1.5,1),COLORGRAY;

Q1809330692的博客 5694

Android.location.Address类方法获取GPS定位信息

参考autojs的获取GPS定位的代码: function getLocationLoop(){ //判断是否已经打开GPS模块 if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {   //GPS模块打开,可以定位操作 var criteria = new Criteria(); criteria.setAccuracy(Criteria

xfxuezhang.cn 2万+

【Bug已解决】NCCL timeout for validation 解决方案

训练用多卡 DDP / FSDP 正常,但一到或者进程直接 hang 在 eval 的某个集合通信上。最迷惑的是:训练阶段(有集合通信)完全正常,偏偏 eval 阶段(看起来更轻量)超时。因为 eval 阶段某些 rank 没参与 collective,导致参与的那部分 rank 永远等不到同伴。

一键难忘的博客 147

8、鼠疫流行过程的计算机建模介绍

本博文介绍了一种基于概率细胞自动机和蒙特卡罗方法的计算机模型,用于模拟由大沙鼠传播的鼠疫流行过程。结合GIS和遥感技术,该模型能够分析鼠疫在不同聚居地类型和季节变化下的传播特征,揭示了群落密度、分布及流行接触率对鼠疫传播的影响。研究还验证了模型与自然流行过程的一致性,并探讨了鼠疫在宿主数量低谷时的持续机制。模型为鼠疫防控和流行病研究提供了定量分析工具。

x2y3z4a5b的博客 109

uniapp 中APP端调用uni.getLocation偶尔获取不到address解决方法

uniapp 中APP端调用uni.getLocation偶尔获取不到address解决方法 1.配置geocode为true uni.getLocation({ type: 'wgs84', geocode:true,//设置该参数为true可直接获取经纬度及城市信息 success: function (res) { console.log('获取定位信息',res); }, fail: function (err) { conso

m0_52459016的博客 9716

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

(转)通过Location获取Address的使用!

我们获取Location的目的之一肯定是有获取这个位置的详细地址,而我们有了Location在来获取Address就相对简单多了,因为GoogleApi已经封装好了方法,我们只需呀通过Location获取GeoPoint,然后在通过GeoPoint来获取我们想要的Address.下面是我做的一个简单的Demo.   第一步新建一个Android工程LocationDemo,注意这里选用

gxj1680的专栏 731

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

上一篇: Android 数据库SQLiteDatabase的使用!!
下一篇: Android中万能的BaseAdapter(Spinner,ListView,GridView)的使用!
shareCode
博客等级 码龄15年 125粉丝 40原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址