使用Google Play服务的Android定位

本文介绍了如何利用Google Play服务API在Android设备上获取用户位置。相较于Android默认的Location API,Google Play Location Services提供了更强大的框架,自动完成位置提供者选择和电源管理,并具备用户活动检测和Geofencing功能。通过GoogleAPIClient可以调用多个Google API,包括Location Services。文章还展示了项目结构和部分代码示例。
摘要由CSDN通过智能技术生成

Welcome to android location using google play services example. Today we will learn how to use Google Play services API to retrieve your mobile location with example app.

欢迎使用Google Play服务示例访问Android位置。 今天,我们将学习如何通过示例应用程序使用Google Play服务API来检索您的移动位置。

Android Location API概述 (Android Location API Overview)

In the previous tutorial, we retrieved the user’s location using Android’s Location API that was available since Android’s API 1. So why was there a need for introducing Google Play Location Services? Why hasn’t Google enhanced Android’s Location API? What are the advantages of Google Play Location Services over the default Android Location API? Let’s discuss these questions to get a clear idea.

在上一教程中,我们使用了Android的位置API(自Android的API 1开始提供)来检索用户的位置。那么为什么需要引入Google Play定位服务? Google为什么没有增强Android的Location API? 与默认的Android Location API相比,Google Play定位服务有哪些优势? 让我们讨论这些问题以获得清晰的想法。

需要引入Google Play定位服务 (Need for introducing Google Play Location Services)

The Google Location Services API, part of Google Play Services, provides a more powerful, high-level framework that automates tasks such as location provider choice and power management. Furthermore, it provides new features such as user’s activity detection that wasn’t available in the Android Framework’s Location API. Currently, Google provides 5 user states which are In Vehicle, On Bicycle, On Foot, Still, and Tilting, which are good enough to detect user’s activity, and to provide right content according to user’s status.
Another feature it provides is Geofencing API that is used to notify a user entering or exiting a particular area.
The above advantages clearly indicate why Google Location Services API(also known as FusedLocationProviderApi) is Google’s recommended way of getting a user’s location. It provides the best accuracy based on our needs.

作为Google Play服务的一部分的Google Location Services API提供了功能更强大的高级框架,该框架可自动执行诸如位置提供商选择和电源管理之类的任务。 此外,它提供了新功能,例如Android Framework的Location API中不提供的用户活动检测。 目前,Google提供了5种用户状态,分别是“车辆内”“自行车上”“步行上” ,“ 静止 ”和“ 倾斜” ,这些状态足以检测用户的活动并根据用户的状态提供正确的内容。
它提供的另一个功能是Geofencing API ,用于通知用户进入或离开特定区域。
上述优势清楚地说明了为什么Google推荐使用Google Location Services API (也称为FusedLocationProviderApi )来获取用户位置。 它可以根据我们的需求提供最佳的准确性。

Google为什么没有增强Android的Location API? (Why hasn’t Google enhanced Android’s Location API?)

From a technical point of view, Google hasn’t improved Android’s Location API since Android has an independent update roll-out feature that lies in the hands of the smartphone manufacturer. Google has less control over it and hence decided to shift to a new API instead.

从技术角度来看,由于Android具有独立的更新推出功能(由智能手机制造商掌握),因此Google并未改进Android的Location API。 Google对它的控制较少,因此决定改用新的API。

There are few important classes that are used to get the location:

有几个重要的类可用于获取位置:

  • LocationRequest : A data object that contains quality of service parameters for requests to the FusedLocationProviderApi. LocationRequest objects are used to request a quality of service for location updates from the FusedLocationProviderApi.

    Location
本帖最后由 espressocafe 于 2011-12-11 12:00 编辑 此GMS包中包括下列全套完整的谷歌服务:   ·电子市场(不是最新版,可安装完以后用电子市场升级)   ·谷歌邮件(不是最新版,可安装完以后用电子市场升级)   ·谷歌日历同步   ·谷歌联系人同步   ·谷歌地图(5.12.1,不是最新版,最新版是6.0.1,可安装完以后用电子市场升级)   ·谷歌纵横   ·谷歌导航   ·谷歌搜索   ·谷歌本地搜索   ·谷歌语音(不是最新版,可安装完以后用电子市场升级)   ·谷歌Talk   刷入前请务必确保手机已经安装Root Explorer或类似软件,且已经Root。用数据线连接电脑,连接模式为仅充电,USB调试模式已打开。(这个连接电脑就是正常的开机连入电脑,不是进什么hboot或什么recovery)      安装方法:   1.将附件下载并解压到X:\adb,因为前期如果您刷机,肯定在您的某块盘上有adb这个文件夹,没有?~~~呃,在别人的教程里下载adb吧,您是怎么root并安装RE的?好吧,您赢了,我已经把adb这个4个文件一并放在包里了。 检查,X:\adb目录里面是否有adb.exe、fastboot.exe等文件,应该不少于4个,咱们这个包解出来是个叫app的文件夹,也在adb目录里,app文件夹进去就是一些后缀名为apk、xml、so的文件,保证他们没有在下层文件夹中。 好了,如果你是XP系统,请按下Win+R,输入CMD回车,然后输入以下命令: cd\ x: (这个X如果是c的话就省略了吧,我的是D,就是换到d盘) cd adb 进入adb文件夹了吧? 如果是win7,简单多了,在图形界面进入X:\adb目录,按住SHIFT键同时点鼠标右键,选在此处打开命令行,呃,也进来了吧? 2.依次输入以下命令: adb shell mkdir sdcard/temp/ (在您手机sd卡上建立了一个叫temp的文件夹) adb push app sdcard/temp/ (把您adb目录下app文件夹中的所有内容拷贝到手机sd卡temp目录中) adb shell (看提示符,是不是已经变成$了?) su (嗯,这下变成#了吧?) 好啦,为了防止出错,有经验的同学可以继续以命令行方式输入cp sdcard/temp/*.apk /system/app/,cp sdcard/temp/*.so /system/lib/,cp sdcard/temp/*.xml /system/etc/permissions/,cp sdcard/temp/*.jar /system/framework/而没经验的同学请先不要管电脑上的命令了,拿起手机打开RE,找到sdcard,进去后找到temp文件夹,进入,用多选模式,把文件夹中的所有的apk文件(一大堆)移动到/system/app文件夹中,把所有的so文件(2个还是3个?)移动到/system/lib文件夹中,把所有的xml 文件(好像就1个)移动到 /system/etc/permissions文件夹中,把所有的jar文件(好像也就1个)移动到/system/framework文件夹中。好了么?sd卡上的temp文件夹也可以顺手删除了,使命已经完成了。别忘了Root Explorer要点击左上角的按钮切换到Mount R/O状态,否则写不进去啊。 好啦,还要统一改一下拷入系统那些文件的权限,都回到电脑上来,那个#还在闪呢!输入: chmod 644 /system/lib/*.so /system/app/*.apk /system/framework/*.jar /system/etc/permissions/*.xml,成功了的表现就是系统给你重复了一遍……(好2啊~~~~) 至此GMS包已全部刷入完毕,重启手机即可。如出现mkdir failed for sdcard/temp/,File exists的提示,则表明手机已经存在temp这个文件夹了,那么继续进行下面的操作即可。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值