How to call to get a single gps fix when ever i want android?(当我想要 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();
如果你想请求一个新的位置,它是更多的代码,我不会在这里介绍.您可以在此处进行一些谷歌搜索或搜索以了解如何使用它.您需要的方法是 requestLocationUpdates 或 requestSingleUpdate.我猜你会更喜欢 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 修复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:当我想要 android 时如何调用以获得单个 gps 修复?
				
        
 
            
        - 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
 - Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
 - Android viewpager检测滑动超出范围 2022-01-01
 - Android - 拆分 Drawable 2022-01-01
 - 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
 - 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
 - android 4中的android RadioButton问题 2022-01-01
 - 用 Swift 实现 UITextFieldDelegate 2022-01-01
 - MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
 - 想使用ViewPager,无法识别android.support.*? 2022-01-01
 
				
				
				
				