不更新,每次都获取安装位置

时间:2016-04-18 04:22:57

标签: android google-maps location

我在后台调用位置更新服务,并优先存储lat-long

  • 我正在使用此lat-long更新当前位置

  • 我可以优先存储lat-long,并且lat-long也会更新

  • 但是当我运行应用程序时,我正在应用程序安装位置获取当前标记,而不是我(我当前位置)。

代码:

  mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .build();
        createLocationRequest();

protected void createLocationRequest() {
        mLocationRequest = new LocationRequest();

        mLocationRequest.setInterval(UPDATE_INTERVAL);
        mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
        mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    }

@Override
public void onLocationChanged(Location location) {

    MarkerOptions mp = new MarkerOptions();
    mp.position(new LatLng(location.getLatitude(), location.getLongitude()));
    mp.title("my position");

    googleMap.setMyLocationEnabled(true);

    if (currentMarker != null) {
        currentMarker.remove();

    }

  dlat = Double.parseDouble(new String(preferenceHelper.getWalkerLatitude()));
     dlong = Double.parseDouble(new String(preferenceHelper.getWalkerLongitude()));

    Log.e("lat-lon",dlat+""+dlong);

    currentMarker = googleMap.addMarker(new MarkerOptions().position(
            new LatLng(location.getLatitude(), location.getLongitude())).title("Your Location"));

}
  • 不知道我哪里错了

0 个答案:

没有答案