如何获得纬度和融合位置APi的经度

时间:2015-10-01 04:58:38

标签: android

我正在使用Fused Location API获取纬度和广度经度。我的问题是如何将这些值设置为其他变量,以便我可以进行一些计算或在我的应用程序上显示它们。到目前为止,我已尝试过以下代码。

public class FusedLocationDetector implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener     {
private Activity context;
private GoogleApiClient mGoogleApiClient;
private Location mLastLocation;
private double temp;
private String mib;
public LocationAddress locationAddress=new LocationAddress();

public FusedLocationDetector(Activity context) {
    mGoogleApiClient=new GoogleApiClient.Builder(context)
            .addApi(LocationServices.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

    mGoogleApiClient.connect();
    this.context=context;
//        locationAddress=new LocationAddress();
}

public  void startConnection(){
    if(mGoogleApiClient!=null){
        mGoogleApiClient.connect();
    }
}

public  void stopConnection(){
    if(mGoogleApiClient!=null){
        mGoogleApiClient.disconnect();
    }
}
@Override
public void onConnected(Bundle bundle) {
    fusedOperation();
}

@Override
public void onConnectionSuspended(int i) {

  //  mGoogleApiClient.connect();
}

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {

}


public void fusedOperation(){
    mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
            mGoogleApiClient);
    if (mLastLocation != null) {
        mib= String.valueOf(mLastLocation.getLatitude());
        locationAddress.setLatitude(mLastLocation.getLatitude());
        locationAddress.setLongitude(mLastLocation.getLongitude());
        Log.d("Longitude",String.valueOf(locationAddress.getLongitude()));
        Log.d("Longitude",mib);



    }
}

}

0 个答案:

没有答案