尊敬的社區,我正在學習在ANDROID谷歌地圖的整合和明白了很多事情,有權限,以及使用最新的GoogleApiAvailability但仍面臨2我無法解決的錯誤。我得到Cannot Resolve Method isUserRecoverableError(int)
AND non-static method getErrorDialog cannot be referenced from a static context in the end of code
在public 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;
}
}
.getInstance()對我來說就像一個魅力。非常感謝您清除我的概念,先生:) –