2017-01-12 4 views
0

Я работаю над доступом к текущему местоположению пользователя и прошел этот учебник Current location и этот учебник Current Location. Все кажется прекрасным, но широта и долгота не появляются в поле TextView.Невозможно получить широту и долготу пользователя в marshmallow

Вот мой код

@Keep 
public class edit_information extends Fragment implements AdapterView.OnItemSelectedListener, GoogleApiClient.ConnectionCallbacks, 
     GoogleApiClient.OnConnectionFailedListener, LocationListener, ResultCallback<LocationSettingsResult> { 
    protected final static String TAG = "EditInformation"; 
    private static final int MY_PERMISSIONS_ACCESS_LOCATION = 1; 
    private RadioGroup radioGroup; 
    private RadioGroup musicRadioGroup; 
    private RadioGroup decorRadioGroup; 
    protected static final int REQUEST_CHECK_SETTINGS = 0x1; 
    //The desired interval for location updates 
    public static final long UPDATE_INTERVAL_IN_MILLISECONDS = 10000; 
    //The fastest rate for active location updates 
    public static final long FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS = UPDATE_INTERVAL_IN_MILLISECONDS/2; 
    //Keys for storing activity state in bundle 
    protected static final String KEY_REQUESTING_LOCATION_UPDATES = "requesting-location-updates"; 
    protected static final String KEY_LOCATION = "location"; 
    protected static final String KEY_LAST_UPDATED_TIME_STRING = "last-updated-time-string"; 
    /* 
    Provides entry point to Google play service 
    */ 
    protected GoogleApiClient mGoogleApiClient; 
    //Store parametrers for request to the FusedLocationProviderApi 
    protected LocationRequest mLocationRequest; 
    //location setting request 
    protected LocationSettingsRequest mLocationSettingsRequest; 
    protected Location mCurrentLocation; 
    //UI 
    protected TextView mLatitudeText; 
    protected TextView mLongitudeText; 
    protected Boolean mRequestingLocationUpdates; 
    protected String mLastUpdateTime; 

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     View view = inflater.inflate(R.layout.edit_information, container, false); 
     Spinner spinner = (Spinner) view.findViewById(R.id.spinner1); 
     Spinner spinner2 = (Spinner) view.findViewById(R.id.spinner2); 

     //Creating an array adapter using the string array and a default spinner layout 
     ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getContext(), R.array.hall_type, simple_spinner_item); 
     ArrayAdapter<CharSequence> adapter1 = ArrayAdapter.createFromResource(getContext(), R.array.hall_size, simple_spinner_item); 

     //Layout to choose the dropdown list 
     adapter.setDropDownViewResource(simple_spinner_dropdown_item); 
     adapter1.setDropDownViewResource(simple_spinner_dropdown_item); 
     spinner.setAdapter(adapter); 
     spinner2.setAdapter(adapter1); 
     spinner.setOnItemSelectedListener(this); 
     spinner2.setOnItemSelectedListener(this); 
     radioGroup = (RadioGroup) view.findViewById(R.id.food_facility); 
     musicRadioGroup = (RadioGroup) view.findViewById(R.id.music_facility); 
     decorRadioGroup = (RadioGroup) view.findViewById(R.id.decor_facility); 
     mLatitudeText = (TextView) view.findViewById(R.id.myLatitude); 
     mLongitudeText = (TextView) view.findViewById(R.id.myLongitude); 
     mRequestingLocationUpdates = false; 
     mLastUpdateTime = ""; 
     updateValuesFromBundle(savedInstanceState); 
     //Start the process of building GoogleApiClient, LocationRequest and LocationSettingRequest 
     buildGoogleApiClient(); 
     createLocationRequest(); 
     buildLocationSettingsRequest(); 
     radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { 
      @Override 
      public void onCheckedChanged(RadioGroup radioGroup, int checkedId) { 
       switch (checkedId) { 
        case R.id.yes: 
         Toast.makeText(getContext(), "Yes", Toast.LENGTH_SHORT).show(); 
         break; 
        case R.id.may: 
         Toast.makeText(getContext(), "May be", Toast.LENGTH_SHORT).show(); 
         break; 
        case R.id.no: 
         Toast.makeText(getContext(), "No", Toast.LENGTH_SHORT).show(); 
         break; 
       } 
      } 
     }); 
     musicRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { 
      @Override 
      public void onCheckedChanged(RadioGroup radioGroup, int i) { 
       switch (i) { 
        case R.id.yesMusic: 
         Toast.makeText(getContext(), "Yes", Toast.LENGTH_SHORT).show(); 
         break; 
        case R.id.mayMusic: 
         Toast.makeText(getContext(), "May be", Toast.LENGTH_SHORT).show(); 
         break; 
        case R.id.noMusic: 
         Toast.makeText(getContext(), "No", Toast.LENGTH_SHORT).show(); 
         break; 
       } 
      } 
     }); 
     decorRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { 
      @Override 
      public void onCheckedChanged(RadioGroup radioGroup, int i) { 

       switch (i) { 
        case R.id.yesDecor: 
         Toast.makeText(getContext(), "Yes", Toast.LENGTH_SHORT).show(); 
         break; 
        case R.id.mayDecor: 
         Toast.makeText(getContext(), "May be", Toast.LENGTH_SHORT).show(); 
         break; 
        case R.id.noDecor: 
         Toast.makeText(getContext(), "No", Toast.LENGTH_SHORT).show(); 
         break; 
       } 
      } 
     }); 
     return view; 
    } 

    @Override 
    public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { 
     Toast.makeText(adapterView.getContext(), "" + adapterView.getItemAtPosition(i).toString(), Toast.LENGTH_SHORT).show(); 
    } 

    @Override 
    public void onNothingSelected(AdapterView<?> adapterView) { 

    } 

    private void updateValuesFromBundle(Bundle savedInstanceState) { 
     if (savedInstanceState != null) { 
      // Update the value of mRequestingLocationUpdates from the Bundle, and make sure that 
      // the Start Updates and Stop Updates buttons are correctly enabled or disabled. 
      if (savedInstanceState.keySet().contains(KEY_REQUESTING_LOCATION_UPDATES)) { 
       mRequestingLocationUpdates = savedInstanceState.getBoolean(
         KEY_REQUESTING_LOCATION_UPDATES); 
      } 

      // Update the value of mCurrentLocation from the Bundle and update the UI to show the 
      // correct latitude and longitude. 
      if (savedInstanceState.keySet().contains(KEY_LOCATION)) { 
       // Since KEY_LOCATION was found in the Bundle, we can be sure that mCurrentLocation 
       // is not null. 
       mCurrentLocation = savedInstanceState.getParcelable(KEY_LOCATION); 
      } 

      // Update the value of mLastUpdateTime from the Bundle and update the UI. 
      if (savedInstanceState.keySet().contains(KEY_LAST_UPDATED_TIME_STRING)) { 
       mLastUpdateTime = savedInstanceState.getString(KEY_LAST_UPDATED_TIME_STRING); 
      } 
      updateUI(); 
     } 
    } 

    protected synchronized void buildGoogleApiClient() { 
     Log.i(TAG, "Building GoogleApiClient"); 
     mGoogleApiClient = new GoogleApiClient.Builder(getContext()) 
       .addConnectionCallbacks(this) 
       .addOnConnectionFailedListener(this) 
       .addApi(LocationServices.API) 
       .build(); 
    } 

    protected void createLocationRequest() { 
     mLocationRequest = new LocationRequest(); 
     mLocationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS); 
     mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS); 
     mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); 
    } 

    protected void buildLocationSettingsRequest() { 
     LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder(); 
     builder.addLocationRequest(mLocationRequest); 
     mLocationSettingsRequest = builder.build(); 
    } 

    protected void checkLocationSettings() { 
     PendingResult<LocationSettingsResult> result = 
       LocationServices.SettingsApi.checkLocationSettings(
         mGoogleApiClient, 
         mLocationSettingsRequest 
       ); 
     result.setResultCallback(this); 
    } 

    @Override 
    public void onResult(LocationSettingsResult locationSettingsResult) { 
     final Status status = locationSettingsResult.getStatus(); 
     switch (status.getStatusCode()) { 
      case LocationSettingsStatusCodes.SUCCESS: 
       Log.i(TAG, "All location settings are satisfied."); 
       startLocationUpdates(); 
       break; 
      case LocationSettingsStatusCodes.RESOLUTION_REQUIRED: 
       Log.i(TAG, "Location settings are not satisfied. Show the user a dialog to" + 
         "upgrade location settings "); 

       try { 
        // Show the dialog by calling startResolutionForResult(), and check the result 
        // in onActivityResult(). 
        status.startResolutionForResult(getActivity(), REQUEST_CHECK_SETTINGS); 
       } catch (IntentSender.SendIntentException e) { 
        Log.i(TAG, "PendingIntent unable to execute request."); 
       } 
       break; 
      case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE: 
       Log.i(TAG, "Location settings are inadequate, and cannot be fixed here. Dialog " + 
         "not created."); 
       break; 
     } 
    } 

    public void onActivityResult(int requestCode, int resultCode, Intent data) { 
     switch (requestCode) { 
      // Check for the integer request code originally supplied to startResolutionForResult(). 
      case REQUEST_CHECK_SETTINGS: 
       switch (resultCode) { 
        case Activity.RESULT_OK: 
         Log.i(TAG, "User agreed to make required location settings changes."); 
         startLocationUpdates(); 
         break; 
        case Activity.RESULT_CANCELED: 
         Log.i(TAG, "User chose not to make required location settings changes."); 
         break; 
       } 
       break; 
     } 
    } 

    public void startUpdatesButtonHandler(View view) { 
     checkLocationSettings(); 
    } 
    public void stopUpdatesButtonHandler(View view) { 
     // It is a good practice to remove location requests when the activity is in a paused or 
     // stopped state. Doing so helps battery performance and is especially 
     // recommended in applications that request frequent location updates. 
     stopLocationUpdates(); 
    } 

    protected void startLocationUpdates() { 
     if (ActivityCompat.checkSelfPermission(getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
      // TODO: Consider calling 
      // ActivityCompat#requestPermissions 
      // here to request the missing permissions, and then overriding 
      // public void onRequestPermissionsResult(int requestCode, String[] permissions, 
      //           int[] grantResults) 
      // to handle the case where the user grants the permission. See the documentation 
      // for ActivityCompat#requestPermissions for more details. 
      return; 
     } 
     LocationServices.FusedLocationApi.requestLocationUpdates(
       mGoogleApiClient, 
       mLocationRequest, 
       this 
     ).setResultCallback(new ResultCallback<Status>() { 
      @Override 
      public void onResult(Status status) { 
       mRequestingLocationUpdates = true; 
      } 
     }); 
    } 

    private void updateUI() { 
     updateLocationUI(); 
    } 

    private void updateLocationUI() { 
     if (mCurrentLocation != null) { 
      mLatitudeText.setText(String.valueOf(mCurrentLocation.getLatitude())); 
      mLongitudeText.setText(String.valueOf(mCurrentLocation.getLongitude())); 
     } 
    } 

    @Override 
    public void onStart() { 
     super.onStart(); 
     mGoogleApiClient.connect(); 
    } 

    @Override 
    public void onResume() { 
     super.onResume(); 
     // Within {@code onPause()}, we pause location updates, but leave the 
     // connection to GoogleApiClient intact. Here, we resume receiving 
     // location updates if the user has requested them. 
     if (mGoogleApiClient.isConnected() && mRequestingLocationUpdates) { 
      startLocationUpdates(); 
     } 
    } 

    @Override 
    public void onPause() { 
     super.onPause(); 
     // Stop location updates to save battery, but don't disconnect the GoogleApiClient object. 
     if (mGoogleApiClient.isConnected()) { 
      stopLocationUpdates(); 
     } 
    } 

    protected void stopLocationUpdates() { 
     // It is a good practice to remove location requests when the activity is in a paused or 
     // stopped state. Doing so helps battery performance and is especially 
     // recommended in applications that request frequent location updates. 
     LocationServices.FusedLocationApi.removeLocationUpdates(
       mGoogleApiClient, 
       this 
     ).setResultCallback(new ResultCallback<Status>() { 
      @Override 
      public void onResult(Status status) { 
       mRequestingLocationUpdates = false; 
      } 
     }); 
    } 

    @Override 
    public void onStop() { 
     super.onStop(); 
     mGoogleApiClient.disconnect(); 
    } 

    @RequiresApi(api = Build.VERSION_CODES.N) 
    @Override 
    public void onConnected(@Nullable Bundle bundle) { 
     Log.i(TAG, "Connected to GoogleApiClient"); 

     // If the initial location was never previously requested, we use 
     // FusedLocationApi.getLastLocation() to get it. If it was previously requested, we store 
     // its value in the Bundle and check for it in onCreate(). We 
     // do not request it again unless the user specifically requests location updates by pressing 
     // the Start Updates button. 
     // 
     // Because we cache the value of the initial location in the Bundle, it means that if the 
     // user launches the activity, 
     // moves to a new location, and then changes the device orientation, the original location 
     // is displayed as the activity is re-created. 
     if (mCurrentLocation == null) { 
      if (ActivityCompat.checkSelfPermission(getContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
       // TODO: Consider calling 
       // ActivityCompat#requestPermissions 
       // here to request the missing permissions, and then overriding 
       // public void onRequestPermissionsResult(int requestCode, String[] permissions, 
       //           int[] grantResults) 
       // to handle the case where the user grants the permission. See the documentation 
       // for ActivityCompat#requestPermissions for more details. 
       return; 
      } 
      mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); 
      mLastUpdateTime = DateFormat.getTimeInstance().format(new Date()); 
      updateLocationUI(); 
     } 
    } 
    public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { 
     switch (requestCode) { 
      case MY_PERMISSIONS_ACCESS_LOCATION: { 
       // If request is cancelled, the result arrays are empty. 
       if (grantResults.length > 0 
         && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 
        updateLocationUI(); 

        // permission was granted, yay! Do the 
        // contacts-related task you need to do. 

       } else { 

        // permission denied, boo! Disable the 
        // functionality that depends on this permission. 
       } 
       return; 
      } 

      // other 'case' lines to check for other 
      // permissions this app might request 
     } 
    } 

    @Override 
    public void onConnectionSuspended(int i) { 
     Log.i(TAG, "Connection suspended"); 
    } 

    @Override 
    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { 
     Log.i(TAG, "Connection failed: ConnectionResult.getErrorCode() = " + connectionResult.getErrorCode()); 
    } 

    @RequiresApi(api = Build.VERSION_CODES.N) 
    @Override 
    public void onLocationChanged(Location location) { 
     mCurrentLocation = location; 
     mLastUpdateTime = DateFormat.getTimeInstance().format(new Date()); 
     updateLocationUI(); 
    } 
    /** 
    * Stores activity data in the Bundle. 
    */ 
    public void onSaveInstanceState(Bundle savedInstanceState) { 
     savedInstanceState.putBoolean(KEY_REQUESTING_LOCATION_UPDATES, mRequestingLocationUpdates); 
     savedInstanceState.putParcelable(KEY_LOCATION, mCurrentLocation); 
     savedInstanceState.putString(KEY_LAST_UPDATED_TIME_STRING, mLastUpdateTime); 
     super.onSaveInstanceState(savedInstanceState); 
    } 
} 

Этих права, которые я добавил в файле манифеста

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


Это XML-код для широты и долгот

<TextView 
     android:id="@+id/myLatitude" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:textSize="15sp" 
     android:textColor="@color/cordinates_color" 
     /> 
    <TextView 
     android:id="@+id/myLongitude" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:textSize="15sp" 
     android:textColor="@color/cordinates_color" 
     /> 

Я добавил эту строку в build.gradle на уровне приложения и синхронизировал проект compile 'com.google.android.gms:play-services:10.0.1'

Мне удалось подключиться к GoogleApiClient, но координаты не подходят. Это проблеск LogCat

01-29 14:49:31.395 10560-10560/com.example.luke.xyz I/EditInformation: Building GoogleApiClient 
01-29 14:49:31.675 10560-10560/com.example.luke.xyz D/ViewRootImpl: #1 mView = android.widget.LinearLayout{2782c80 V.E...... ......I. 0,0-0,0} 
01-29 14:49:31.715 10560-10616/com.example.luke.xyz D/mali_winsys: new_window_surface returns 0x3000, [468x91]-format:1 
01-29 14:49:31.755 10560-10560/com.example.luke.xyz I/EditInformation: Connected to GoogleApiClient 
01-29 14:49:31.805 10560-10616/com.example.luke.xyz V/RenderScript: 0xdc179000 Launching thread(s), CPUs 8 

Я проверяю его на Android Зефир. Все еще неспособный понять это.
Вы можете мне помочь?
Спасибо

+0

Вы не пользовались разрешениями пролета врезания –

+0

Я добавил эту строку int permissionCheck = ContextCompat.checkSelfPermission (getContext(), Manifest.permission.ACCESS_FINE_LOCATION); –

+0

Вы должны добавить и проверить разрешение для ACCESS_COURSE_L OCATION также –

ответ

1

Ask запустить разрешения времени, как это:

// Here, thisActivity is the current activity 
if (ContextCompat.checkSelfPermission(thisActivity, 
       Manifest.permission.ACCESS_COURSE_L‌​OCATION) 
     != PackageManager.PERMISSION_GRANTED) { 

    // Should we show an explanation? 
    if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity, 
      Manifest.permission.ACCESS_COURSE_L‌​OCATION)) { 

     // Show an explanation to the user *asynchronously* -- don't block 
     // this thread waiting for the user's response! After the user 
     // sees the explanation, try again to request the permission. 

    } else { 

     // No explanation needed, we can request the permission. 

     ActivityCompat.requestPermissions(thisActivity, 
       new String[]{Manifest.permission.ACCESS_COURSE_L‌​OCATION}, 
       MY_PERMISSIONS_REQUEST_LOCATION); 

     // MY_PERMISSIONS_REQUEST_LOCATION is an 
     // app-defined int constant. The callback method gets the 
     // result of the request. 
    } 
} 

Тогда:

@Override 
public void onRequestPermissionsResult(int requestCode, 
     String permissions[], int[] grantResults) { 
    switch (requestCode) { 
     case MY_PERMISSIONS_REQUEST_LOCATION: { 
      // If request is cancelled, the result arrays are empty. 
      if (grantResults.length > 0 
       && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 

       // permission was granted, yay! Do the 
       // contacts-related task you need to do. 

      } else { 

       // permission denied, boo! Disable the 
       // functionality that depends on this permission. 
      } 
      return; 
     } 

     // other 'case' lines to check for other 
     // permissions this app might request 
    } 
} 

более подробную информацию вы можете найти здесь: https://developer.android.com/training/permissions/requesting.html

+0

Должен ли я включать все в метод OnConnected()? –

+0

перед сборкой вам нужно спросить. поместите код сборки внутри разрешения. – Spartan

+0

Все еще не в состоянии разобраться. –

0

Перейти к Настройки> Приложения> Your_app, а также в разрешениях tab, enable Местоположение для мгновенного получения выхода на Зефир.

0

Использование и расположение Permission - ACCESS_COARSE_LOCATION , ACCESS_FINE_LOCATION, то же время использование Double для LatLng:

@Override 
public void onConnected(@Nullable Bundle connectionHint) { 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 

     if (ActivityCompat.checkSelfPermission 
       (getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED 
       && 
       ActivityCompat.checkSelfPermission 
         (getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) 
     { 
      requestPermissions(new String[]{ 
        Manifest.permission.ACCESS_COARSE_LOCATION, 
        Manifest.permission.ACCESS_FINE_LOCATION 
      }, 1); 
      return; 

     } 
    } 
    else{ 
     Location mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); 
     if(mLastLocation!=null){ 
     mLatitudeText.setText(Double.parseDouble(mLastLocation.getLatitude())); 
     mLongitudeText.setText(Double.parseDouble(mLastLocation.getLongitude())); 
     }else { 
       Toast.makeText(getContext(),"LOcation is null",Toast.LENGTH_SHORT).show(); 
       } 

    } 

} 

Ручка просил Permission:

@Override 
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 
    switch (requestCode) { 

     case 1: 
      if (grantResults[0] != PackageManager.PERMISSION_GRANTED){ 
       Toast.makeText(getContext(),"PERMISSION_GRANTED",Toast.LENGTH_SHORT).show(); 
       } 
       else { 
        Toast.makeText(getContext(),"PERMISSION_GRANTED",Toast.LENGTH_SHORT).show(); 
       } 
      break; 
     } 
    } 
+0

По-прежнему нет помощи! –

+0

Должен ли я включать эти строки кода в onRequestPermissionResult в инструкции else? Местоположение mlastLocation = LocationServices.FusedLocationApi.getLastLocation (mGoogleApiClient); if (mLastLocation! = Null) { mLatitudeText.setText (Double.parseDouble (mLastLocation.getLatitude())); mLongitudeText.setText (Double.parseDouble (mLastLocation.getLongitude())); } –

+0

Я получаю ошибку в строке, содержащей это Я изменил ее на getContext(), И я думаю, что мне не нужно преобразовывать ее в double, поскольку я принимаю значения в String, как этот String.valueOf (mLastLocation.getLatitude ()); Надеюсь, это сработает. Правильно ? –

0

Ваше кодирование прекрасно вам просто нужно добавить немного больше разрешение манифеста файл

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


Убедитесь, что ваш GPS включен. Сообщите мне, если это исправить вашу проблему.

+0

Как разрешение LOCATION_HARDWARE помогает нам захватить местоположение пользователя? –

+0

Позволяет приложению использовать функции местоположения на оборудовании, например, geofencing api. Перейдите по этой ссылке для получения дополнительной информации https://developer.android.com/reference/android/Manifest.permission.html#LOCATION_HARDWARE – Lokesh

+0

Ни один человек, который еще не получает координаты –

0

В настоящее время вы запрашиваете последнее известное местоположение в onConnected. Если нет кэшированного местоположения, это ничего не сделает.

Вы должны переопределить onLocationChanged, чтобы получать текущее местоположение после подключения вашего клиента Google API. https://developer.android.com/training/location/receive-location-updates.html#callback


GoogleApiClient.connect метод является асинхронным. В документации, приведенной выше, запрос на обновление местоположения производится после подключения GoogleApiClient. Вы делаете этот запрос в onResume, но не гарантируется, что GoogleApiClient подключен до onConnected. Сделайте запрос в onConnected, как показывает пример в документации.

+0

Позвольте мне посмотреть, если это работает. –

+0

привет, я все еще не могу захватить координаты. Я прошел всю документацию. И обновил мой код. Вы можете помочь мне здесь. –

+0

Странно, что я обновил код, я протестировал один и тот же код в методе onCreate(), который отображает координаты, но он не работает в методе onCreateView(). Я не думаю, что это будет иметь значение в соответствии с этим ответом http://stackoverflow.com/questions/28929637/difference-and-uses-of-oncreate-oncreateview-and-onactivitycreated-in-fra right? –