問(wèn)題描述
我有一項(xiàng)服務(wù),它通過(guò)注冊(cè) LocationManager.requestLocationUpdates
來(lái)接收位置.但是有些手機(jī)出現(xiàn)了一些問(wèn)題.
I have a service which receives locations through registering a LocationManager.requestLocationUpdates
.
But there have been some issues on some phones.
當(dāng)電池電量不足時(shí),網(wǎng)絡(luò)位置提供程序會(huì)停止發(fā)送位置修復(fù)(此問(wèn)題已在 這個(gè) SO 問(wèn)題).這不僅是我的應(yīng)用程序的問(wèn)題,而且其他應(yīng)用程序也只是停止接收位置.即使手機(jī)已充電,問(wèn)題仍然存在,直到完全重新啟動(dòng).
When battery runs low, the network location provider stops sending location fixes (this problem is addressed in this SO question). It's not a only a problem with my app but also the other apps just stop receiving locations. Even when the phone is recharged the problem persists until the full reboot.
但是,我發(fā)現(xiàn)(并且有人在上面的 SO 問(wèn)題中也提到過(guò))Google 地圖仍然不斷接收位置更新 - 當(dāng)我打開(kāi) Google 地圖應(yīng)用時(shí),它會(huì)顯示正確的位置和更新.
However, I found out (and someone also mentioned it in the SO question above) that Google Maps still keeps receiving location updates - when I open Google Maps app it shows the correct location and updates.
所以我正在考慮使用 Google Maps API 中的位置的解決方法.我完全沒(méi)有使用 Maps API 的經(jīng)驗(yàn),但它似乎需要一個(gè)適當(dāng)?shù)?GUI (Activity) 應(yīng)用程序才能使用.還是我錯(cuò)了?是否有可能使用 Google Maps API 甚至在服務(wù)內(nèi)接收位置?
So I was thinking about a workaround of using locations from Google Maps API. I have absolutely no experience with the Maps API, but it seems that it needs a proper GUI (Activity) application to be used with. Or am I wrong? Is there a possibility to use Google Maps API to receive locations even within the Service?
推薦答案
鑒于可靠來(lái)源的一些廣泛測(cè)試,我相信您可能需要考慮使用 Google Play 服務(wù)提供的 FusedLocationProvider.選擇合適的功率標(biāo)準(zhǔn)等似乎讓您頭疼.
Given some extensive testing from a reliable source, I believe that you might want to consider using the FusedLocationProvider supplied with Google Play Services. It seems to take the headache out of choosing the appropriate power criteria and so on.
請(qǐng)注意,這將要求用戶必須在其設(shè)備上安裝 Google Play,因此 Kindle 等設(shè)備將無(wú)法使用.它還需要至少 Android 2.2.
Be aware that this will require that the user must have Google Play installed on their device, so Kindles and the like will be out of the picture. It also requires a minimum of Android 2.2.
有關(guān) Google Play 服務(wù)提供的定位服務(wù)的更多信息,請(qǐng)參閱這里一個(gè)>.
Some more information about the location services provided by Google Play Services can be found here.
這篇關(guān)于在沒(méi)有活動(dòng)的情況下使用 Google 地圖位置的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!