1

Im developing an android application for china which will need GPS location tracking. For location tracking android needs access to Google play services.But Google play services is blocked for china.

Any workaround for this issue ? Any recommended 3rd party library or implementation?

Thanks

Ramindu Weeraman
  • 344
  • 2
  • 10
  • 1
    You can use traditional gps location collection and filtering yourself. You may already known this https://developer.android.com/guide/topics/location/strategies.html – james Oct 21 '16 at 07:40
  • Thanks.I use above code to get location in chinese tablet(Huawei M2 -A01L) and its not working. Any idea ? – Ramindu Weeraman Oct 24 '16 at 01:28

2 Answers2

3

You should use android.location.LocationManager from the system, implement the LocationListener, and call the requestLocationUpdates on the 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);

For more information see dosc and this answer.

Community
  • 1
  • 1
Sergey Nikitin
  • 807
  • 8
  • 23
0
  1. LocationManager, doesn't require Google Play Services. This documentation mentions about it perfectly https://developer.android.com/guide/topics/location/strategies.html
  2. BaiduLocation, seems like this is suitable for China and doesn't have English documentation. AFAIK, Wechat uses this too, http://developer.baidu.com/map/geosdk-android-developv3.3.htm

Almost i don't have any experience on BaiduLocation. All documentation is Chinese. If you look below link, it mentions about location modes like Device_Sensors, Battery_Saving, Hight_Accuracy. Maybe this is what you wish.

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

        }
    });
}
blackkara
  • 4,900
  • 4
  • 28
  • 58
  • Thanks,Is BaiduLocation can get the location without internet connectivity ?Like we can do it using Google play service (using GPS provider) – Ramindu Weeraman Oct 27 '16 at 04:02