获取android应用的当前位置地址 [英] Get current location address for android app

查看:26
本文介绍了获取android应用的当前位置地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不需要显示地图.但是,我需要使用 gps/3g 网络来定位我当前的位置 ADDRESS(不是经纬度),然后这将被添加到自动短信响应中,以通知某人我目前无法回复,&包括我当前位置的字符串地址.我有短信工作,只需要找出一种访问gps和提取地址的方法.我已经看到了 lat/long 的示例代码.也许我需要将 lat/long 转换为 google maps API 中的地址?我不确定如何去做.欢迎任何建议/代码片段/类似教程!谢谢.:)

I do not need to display a map. However, I need to use the gps/3g network to locate my current positions ADDRESS (not long and lat) this will then be added to a automated sms response to inform a person that I currently cant reply, & the include the string address of my current location. I have the sms stuff working, just need to figure out a method of accessing the gps and pulling an address. I have seen sample code for lat/long. Perhaps I need to convert lat/long into an address within the google maps API? I am unsure howto go about it. Any advice/code snippets/similar tutorials welcome! Thanks. :)

推荐答案

有两个步骤:

  1. 获取当前位置 - 纬度 &经度,使用 GPS、网络、最后已知位置等 Android 位置文档包括示例代码.

使用 Android Geocoder 类 请求查找将纬度/经度转换为地址(您可以轻松地从中提取城市、国家、街道等).具体来说,需要使用getFromLocation()方法

Use the Android Geocoder class to request a lookup to convert the lat/long to an Address (from which you can easily extract city, country, street, etc). Specifically, you need to use the getFromLocation() method

注意:

  • getFromLocation() 方法返回一组匹配项.在某些情况下,您可以向用户展示一组(例如 5 个)并让他们选择最好的一个,或者您可以只使用第一个,假设它是最好的.
  • 请记住,这两个调用都需要时间.GPS/网络可能需要一段时间才能提供位置.同样,对 getFromLocation() 的调用可能需要一些时间,因为它会通过网络到达 Google Maps API.因此,您必须对各种场景使用广泛的错误处理,并且将这两个调用移到单独的线程上,这样您就不会锁定应用用户界面(查看 AsyncTask)
  • Geocoder 类后端仅存在于 Google 批准的设备上.因此,在任何没有 GMail/Market/Maps 的设备上,查找基本上都会失败.

这篇关于获取android应用的当前位置地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆