In this GPS tutorial you will learn how to get current location in android.
在本GPS教程中,您将学习如何在android中获取当前位置。
LocationManager class provides the facility to get latitude and longitude coordinates of current location. The class in which you want to get location should implement LocationListener and override all its abstract methods.
LocationManager类提供了获取当前位置的纬度和经度坐标的工具。 您要在其中获取位置的类应实现LocationListener并覆盖其所有抽象方法。
如何使用位置管理器在Android中获取当前位置 (How to Get Current Location in Android Using Location Manager)
Add following permissions to AndroidManifest.xml file.
向AndroidManifest.xml文件添加以下权限。
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
Following lines of code helps in getting current location.
以下代码行有助于获取当前位置。
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 5, this);
In requestLocationUpdates() method the 2nd argument is time in milliseconds and 3rd argument is distance in meters. Here I have used 5000 and 5 that means after every 5 seconds and 5 meter the current location is f