Gps On App only works after Using Google Maps

2019-07-03 23:47发布

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

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?

2条回答
祖国的老花朵
2楼-- · 2019-07-04 00:36

Try this:- we have to register location listener with the locationManager.onLocationChanged method will be execute, when we provide locationlitener

 locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
 100, 0, this, locationlistener);
查看更多
我只想做你的唯一
3楼-- · 2019-07-04 00:46

You need to turn on GPS first:

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.

查看更多
登录 后发表回答