android– 如何在没有跟踪的情况下只获取一次用户位置?

android– 如何在没有跟踪的情况下只获取一次用户位置?,第1张

概述在我的Android应用程序中,我需要在单击按钮时gt用户位置.但是,我不需要接收有关其位置的持续更新.我在stackoverflow上搜索了几个问题,但答案是2–3年,所以我想知道,就像AndroidSDK现在一样,最好的方法是什么.另外,如果可能的话,我不想在该位置获取null.提前致谢.解决方法:

在我的Android应用程序中,我需要在单击按钮时gt用户位置.但是,我不需要接收有关其位置的持续更新.

我在stackoverflow上搜索了几个问题,但答案是2 – 3年,所以我想知道,就像AndroID SDK现在一样,最好的方法是什么.

另外,如果可能的话,我不想在该位置获取null.

提前致谢.

解决方法:

我知道这个问题很老,但万一有人还需要知道答案.
您可以使用setNumUpdates方法并传递值1.
例:

mLocationRequest = new LocationRequest();mLocationRequest.setNumUpdates(1);mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

By default locations are continuously updated until the request is explicitly removed, however you can optionally request a set number of updates. For example, if your application only needs a single fresh location, then call this method with a value of 1 before passing the request to the location clIEnt.

https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.html#setNumUpdates(int)

总结

以上是内存溢出为你收集整理的android – 如何在没有跟踪的情况下只获取一次用户位置?全部内容,希望文章能够帮你解决android – 如何在没有跟踪的情况下只获取一次用户位置?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1119651.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存