我想添加一个包含当前位置的Google地图。我怎样才能做到这一点?我找到了这个代码,但位置是静态的。我该如何纠正?
ExifInterface exif;
try {
exif = new ExifInterface(photoPath);
}
catch (IOException e) {
e.printStackTrace();
exif = null;
}
if(exif!=null){
orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
}
//get Bitmap
Bitmpam bitm = ..... ;//uploaded file
if(orientation==8){
Matrix matrix = new Matrix();
matrix.postRotate(270);
bitm = Bitmap.createBitmap(bitm, 0, 0, bitm.getWidth(), bitm.getHeight(), matrix, true);
}
if(orientation==6){
Matrix matrix = new Matrix();
matrix.postRotate(90);
bitm = Bitmap.createBitmap(bitm, 0, 0, bitm.getWidth(), bitm.getHeight(),matrix,true);
}
if(orientation==3){
Matrix matrix = new Matrix();
matrix.postRotate(180);
bitm = Bitmap.createBitmap(bitm, 0, 0, bitm.getWidth(), bitm.getHeight(),matrix,true);
}
答案 0 :(得分:0)
试试这个
private void displayLocation() {
LocationRequest locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(30 * 1000);
locationRequest.setFastestInterval(5 * 1000);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(locationRequest);
// **************************
builder.setAlwaysShow(true); // this is the key ingredient
// **************************
PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi
.checkLocationSettings(mGoogleApiClient, builder.build());
result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
@Override
public void onResult(LocationSettingsResult result) {
final Status status = result.getStatus();
final LocationSettingsStates state = result.getLocationSettingsStates();
switch (status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:
// All location settings are satisfied. The client can
// initialize location
// requests here.
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
dialog.setMessage(context.getResources().getString(R.string.allow_location));
dialog.setPositiveButton(context.getResources().getString(R.string.yes),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface paramDialogInterface, int paramInt) {
progressDialog = Utility.getProgressDialog(context);
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setCancelable(false);
if (progressDialog != null) {
progressDialog.show();
}
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// Do something after 5s = 5000ms
progressDialog.dismiss();
Location mLastLocation = LocationServices.FusedLocationApi
.getLastLocation(mGoogleApiClient);
if (mLastLocation != null) {
setUpMap(mLastLocation.getLatitude(), mLastLocation.getLongitude(), "Current Location",
true);
}
}
}, 4000);
}
});
dialog.setNegativeButton(context.getString(R.string.no), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface paramDialogInterface, int paramInt) {
setUpMap(12.9667, 77.5667, "", false);
Utility.showToat(context, "Select Address from the Map");
}
});
dialog.setCancelable(false);
dialog.show();
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
// Location settings are not satisfied. But could be fixed
// by showing the user
// a dialog.
try {
// Show the dialog by calling
// startResolutionForResult(),
// and check the result in onActivityResult().
status.startResolutionForResult(GoogleMapActivity.this, REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException e) {
// Ignore the error.
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
// Location settings are not satisfied. However, we have no
// way to fix the
// settings so we won't show the dialog.
break;
}
}
});
}