使用gps从纬度和经度获取当前位置

问题描述 投票:-1回答:2

我使用Telnet在模拟器中获得了纬度和经度值。(即)GPS。

我怀疑(即)没有谷歌地图我们能够使用纬度和经度获得当前位置。

android android-ndk location
2个回答
0
投票

您可以使用GPS和Google地图同时获取当前位置。如果你想通过谷歌地图获取位置,那么请参阅plz show this教程。你可以see this上一个问题。

如果您想在没有Google地图的情况下获取位置,那么您可以使用位置管理器。

为此,我们需要在OnCreate方法中添加以下代码:

/* Use the LocationManager class to obtain GPS locations */
LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);

在自定义类MyLocationListener中使用实现接口LocationListener。

我们将添加我们自己的个人位置监听器,因此我们可以覆盖一些功能来做我们想要的。在我们的例子中,我们将在以下情况下向屏幕打印一条消息:

onLocationChanged ( Location Update )
onProviderDisabled ( GPS Off )
onProviderEnabled (GPS On )

并添加另一个强制方法,它什么都不做。

onStatusChanged (We are not adding nothing here).

之后,在AndroidManifest.xml文件中给出权限:

android:name="android.permission.ACCESS_FINE_LOCATION"

0
投票

您可以通过此代码获得纬度和经度

GPS_Location mGPS = new GPS_Location(MyApplication.getAppContext());

if (mGPS.canGetLocation) {

    mLat = mGPS.getLatitude();
    mLong = mGPS.getLongitude();

} else {
    System.out.println("cannot find");
}

您必须为您的应用添加gps权限和其他权限

© www.soinside.com 2019 - 2024. All rights reserved.