当我想要 android 时如何调用以获得单个 gps 修复? [英] How to call to get a single gps fix when ever i want android?

查看:13
本文介绍了当我想要 android 时如何调用以获得单个 gps 修复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何仅通过调用一个函数来获得我所在位置的单个 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://developer.android.com/reference/android/location/Location.htmlhttp://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

但要获取最近的位置并将其显示在 Toast 中:

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();

如果你想请求一个新的位置,它是更多的代码,我不会在这里介绍.您可以在此处进行一些谷歌搜索或搜索以了解如何使用它.您需要的方法是 requestLocationUpdatesrequestSingleUpdate.我猜你会更喜欢 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

这篇关于当我想要 android 时如何调用以获得单个 gps 修复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆