问题描述
我们有一个使用地图API这个Android应用程序。现在,当我们运行它,它通常不工作,当我们调用
We have this android app that uses the maps api. Now when we run it, it usually doesn't work, when we call
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
100, 0, this, null);
这并不工作,LocationListener的的onLocationChanged方法不会被调用。但是,如果我们运行谷歌地图,等待GPS图标在状态栏,然后我们的应用程序并开始呼叫onLocationChanged。所以我的问题是,如何为谷歌地图激活全球定位系统,或者如果他们不将其激活,他们在做什么?
It doesn't really work, the LocationListener's onLocationChanged method is never called. However, if we run Google Maps and wait until the gps icon is on in the status bar, then our app does start calling onLocationChanged. So my question is, how is Google Maps "activating" gps, or if they're not activating it, what are they doing?
推荐答案
您需要先开启GPS:
try {
Settings.Secure.setLocationProviderEnabled(getContentResolver(), LocationManager.GPS_PROVIDER, true);
} catch (Exception e) {
logger.log(Log.ERROR, e, e.getMessage());
}
要做到这一点,你还需要有从最终用户,我相信权限。
To do that, you also need to have permission from end-user i believe.
这篇关于GPS在App只使用谷歌地图后工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!