我是 android 新手,我在 GEoFencing 类 googlemap 中遇到两天错误。所以请提供更好的解决方案
public class GeoFencingeg extends Activity implements ConnectionCallbacks,OnConnectionFailedListener,LocationListener{
LocationRequest lr;
GoogleApiClient mclient;
TextView txt;
Location mLastLocation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_geo_fencingeg);
txt=(TextView)findViewById(R.id.tv);
lr=LocationRequest.create();
mLastLocation=new Location("");
Toast.makeText(getApplicationContext(), "Google API"+GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()), Toast.LENGTH_LONG).show();
try{
mclient=new GoogleApiClient.Builder(this).addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API,new Plus.PlusOptions.Builder().build())
.addScope(Plus.SCOPE_PLUS_LOGIN).build();
mclient.connect();
}
catch(Exception e){
Log.i("Exception", e.getMessage());
}
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
if(mclient.isConnected())
mclient.disconnect();
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
txt.setText("Current Location"+location.toString());
}
@Override
public void onConnectionFailed(ConnectionResult arg0) {
// TODO Auto-generated method stub
}
@Override
public void onConnected(Bundle arg0) {
// TODO Auto-generated method stub
lr.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
lr.setInterval(1000);
LocationServices.FusedLocationApi.requestLocationUpdates(mclient, lr, this);
}
@Override
public void onConnectionSuspended(int arg0) {
// TODO Auto-generated method stu
}
}
在编译错误时,在 GoogleApiClient.Builder().Build() 中发现了未知来源。
最佳解决方案