无法在 android 中获取当前纬度和经度

Not able to fetch current latitude and longitude in android

我是 android 的新人,我正在尝试获取我当前位置的经纬度,为此我正在使用 'com.google.android.gms:play-services:8.4。 0' 我收到了这个错误
java.lang.IllegalArgumentException:需要 GoogleApiClient 参数。 我参考了以前的 stckoverflow 答案,但它没有帮助 me.Please 帮助我,在此先感谢

这里是Mapsactivity.java

的代码
   public class MapsActivity extends FragmentActivity{

   private GoogleMap mMap;
AppLocationService appLocationService;
GoogleApiClient mGoogleApiClient;
private Location mLastLocation;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
   setUpMapIfNeeded();
} 

  private void setUpMapIfNeeded() {
    if (mMap == null) {

        mMap = ((SupportMapFragment) 
          getSupportFragmentManager().findFragmentById(R.id.map))
                .getMap();

        if (mMap != null) {

            displayLocation();
        }
    }
}
private void displayLocation() {

    mLastLocation = LocationServices.FusedLocationApi
            .getLastLocation(mGoogleApiClient);

    if (mLastLocation != null) {
        double latitude = mLastLocation.getLatitude();
        double longitude = mLastLocation.getLongitude();

        Log.d("result", latitude + ", " + longitude);

    } else {

      Log.d("result2","(Couldn't get the location. Make sure location is
   enabled on the device)");
     }
 }
}

这是我的清单文件的代码

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.malli.myapplication" >

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission  
 android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" 
/>

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="@string/google_maps_key" />

    <activity
        android:name=".MapsActivity"
        android:label="@string/title_activity_maps" >
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version"/>
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

您还没有初始化您的 mGoogleApiClient 变量。请先初始化。

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

 mLastLocation = LocationServices.FusedLocationApi
            .getLastLocation(mGoogleApiClient);

注意:这只是初始化 GoogleApiClient 的示例