我正在为中国开发一个需要GPS位置跟踪的Android应用程序。 对于位置跟踪,Android需要访问Google Play服务。但谷歌播放服务被阻止用于中国。
此问题的解决方法是什么?任何推荐的第三方库或实施?
由于
答案 0 :(得分:2)
您应该使用系统中的android.location.LocationManager
,实施LocationListener
,并致电requestLocationUpdates
上的LocationManager
// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
// Called when a new location is found by the network location provider.
makeUseOfNewLocation(location);
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
答案 1 :(得分:0)
几乎我对百度位置没有任何经验。所有文件都是中文。如果你看下面的链接,它会提到像Device_Sensors,Battery_Saving,Hight_Accuracy这样的位置模式。也许这就是你想要的。
http://wiki.lbsyun.baidu.com/cms/androidloc/doc/v7.0/index.html
// This is simplified example from github
// https://github.com/buqing2009/GCS_Baidu_Advance/blob/master/app/src/main/java/com/lingmutec/buqing2009/gcs_baidu_advance/BaiduMapFragment.java
private LocationClient mLocationClient = null;
public void requestLocationUpdates() {
mLocationClient = new LocationClient(getApplicationContext());
LocationClientOption option = new LocationClientOption();
option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
option.setOpenGps(true);
option.setCoorType("bd09ll");
option.setScanSpan(1000);
mLocationClient.setLocOption(option);
mLocationClient.registerLocationListener(new BDLocationListener() {
@Override
public void onReceiveLocation(BDLocation location) {
}
});
}