如何调用得到一个GPS定位当过我想要的android?当过、我想要、GPS、android

2023-09-05 05:10:44 作者:她的剑很冷

我怎样才能得到我的位置的单一GPS定位只是通过调用一个函数?就为了这个例子我怎么能得到纬度和经度为干杯。

How can I get a single GPS fix of my location just by calling one function? Just for this example how can I get the Lat and Lon into a toast.

推荐答案

你尝试过什么?

下面是两个的位置的官方网页:的http://开发商。 android.com/reference/android/location/Location.html http://developer.android.com/reference/android/location/LocationManager.html

Here are two of the official pages for location: http://developer.android.com/reference/android/location/Location.html http://developer.android.com/reference/android/location/LocationManager.html

但要获得最新的位置,并显示在举杯:

But to get the most recent location and show it in a Toast:

LocationManager locMan = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
Location loc = locMan.getLastKnownLocation(LocationManager.GPS_PROVIDER);
String lat = String.valueOf(loc.getLatitude());
String longitude = String.valueOf(loc.getLongitude());
Toast.makeText(context, lat+","+longitude, Toast.LENGTH_LONG).show();

如果你想申请一个新的位置,更code,我将不包括在这里。你可以做一些谷歌搜索或搜索在此处,了解如何使用它。你需要的方法是 requestLocationUpdates requestSingleUpdate 。我猜你会preFER requestSingleUpdate

If you want to request a new location, it is more code, and I will not cover that here. You can do some google searching or searching on here to find how to use it. The method you need is requestLocationUpdates or requestSingleUpdate. I'm guessing you would prefer requestSingleUpdate

 
精彩推荐
图片推荐