2016-11-01 105 views
1

尊敬的社區,我正在學習在ANDROID谷歌地圖的整合和明白了很多事情,有權限,以及使用最新的GoogleApiAvailability但仍面臨2我無法解決的錯誤。我得到Cannot Resolve Method isUserRecoverableError(int) AND non-static method getErrorDialog cannot be referenced from a static context in the end of codepublic boolean ServicesOK()方法。 以下是Java代碼:(如果需要其他任何東西,請讓我知道,這樣我可以適當採用Android谷歌地圖的概念:)引導)來自GooglePlayServicesUtil不是來自GoogleApiAvailability基本谷歌地圖Android版,2個小錯誤的權限

package com.example.testmap; 

import android.app.Dialog; 
import android.os.Bundle; 
import android.support.v4.app.FragmentActivity; 
import android.widget.Toast; 

import com.google.android.gms.common.ConnectionResult; 
import com.google.android.gms.common.GoogleApiAvailability; 
import com.google.android.gms.common.GooglePlayServicesUtil; 
import com.google.android.gms.maps.CameraUpdateFactory; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.OnMapReadyCallback; 
import com.google.android.gms.maps.SupportMapFragment; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.MarkerOptions; 

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { 

    private static final int ERROR_DIALOG_REQUEST = 9901; 

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

     if(ServicesOK()) { 
      Toast.makeText(this, "Can't connect to mapping services", Toast.LENGTH_SHORT).show();} 

      // Obtain the SupportMapFragment and get notified when the map is ready to be used. 
      SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
        .findFragmentById(R.id.map); 
      mapFragment.getMapAsync(this); 
     } 

    @Override 
    public void onMapReady(GoogleMap googleMap) { 
     GoogleMap mMap = googleMap; 

     // Add a marker in Sydney and move the camera 
     LatLng sydney = new LatLng(-34, 151); 
     mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); 
     mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); 
    } 

    public boolean ServicesOK(){ 
     GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance(); 
     int isAvailable = googleApiAvailability.isGooglePlayServicesAvailable(this); 

     if(isAvailable== ConnectionResult.SUCCESS){ 
      return true; 
     } 
     else if(GoogleApiAvailability.isUserRecoverableError(isAvailable)){ 
      Dialog dialog; 
      dialog= GoogleApiAvailability.getErrorDialog(isAvailable, this, ERROR_DIALOG_REQUEST); 
      dialog.show(); 
     } 
     else{ 
      Toast.makeText(this, "Can't connect to mapping services", Toast.LENGTH_SHORT).show(); 
     } 
     return false; 
    } 
} 

回答

1

isUserRecoverableError方法。但正如您在文檔中看到的,此方法已被棄用,您現在應該使用GoogleApiAvailability.getInstance().isUserResolvableError()而不是

並針對第二個錯誤嘗試訪問getErrorDialog,但這不是一種靜態方法。相反,你應該做GoogleApiAvailability.getInstance().getErrorDialog

+0

.getInstance()對我來說就像一個魅力。非常感謝您清除我的概念,先生:) –

相關問題