也可通过单击manifest.xml文件的permission标签可视化的添加许可
/**********************************************************************************************************************/
第二部分 认识LocationManager
官方SDK解释“This class provides access to the system location services. These services allow applications to obtain periodic updates of the device's geographical location, or to fire an application-specified Intent
when the device enters the proximity of a given geographical location.
You do not instantiate this class directly; instead, retrieve it through Context.getSystemService(Context.LOCATION_SERVICE). ”
翻译一下大概意思是“LocationManager这个类提供了对系统位置服务的访问,这些服务允许应用程序获取设备地理位置的定期的更新,也可以在设备接近一个指定的地理位置的时候发起一个指定activity的intent。你不需要创建LocationManager的实例,取而代之的是通过Context.getSystemService(Context.LOCATION_SERVICE)获取。”
重要的方法:来自官方SDK(附上我的翻译注释)
-----------------------------------------------------------------------------------------------------------------------------------------------
public Location getLastKnownLocation (String provider)
Since: API Level 1
Returns a Location indicating the data from the last known location fix obtained from the given provider. This can be done without starting the provider. Note that this location could be out-of-date, for example
if the device was turned off and moved to another location.
//返回一个Location,这个location标明从给定provider获得最后已知的位置,也就是最近获取的位置。这个操作可以不必要启动provider,注意这个地址可能是已经过期的,例如使用的设备可能已经被关闭或者转向了另一个位置。