修复了另一个连接问题后,现在我有了这个:我无法点击“确定”。在对话框中处理位置权限,仅在拒绝。
如果我以手动方式(通过设置)授予权限,我在日志中有这个:
W / DynamiteModule:找不到com.google.android.gms.googlecertificates的本地模块描述符类。
但是我创建了密钥并获得了json文件。
这是我的简单活动:
package com.marcocreation.***********;
import *;
public class Maps extends AppCompatActivity implements OnClickListener, OnMapReadyCallback, ActivityCompat.OnRequestPermissionsResultCallback, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
private GoogleMap mMap;
private Location mLastLocation;
private GoogleApiClient mGoogleApiClient;
private static final int REQUEST_LOCATION = 1503;
private double latitude, longitude;
private static final int LOCATION_PERMISSION_REQUEST_CODE = 1;
private boolean mPermissionDenied = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Create an instance of GoogleAPIClient.
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(this);
// 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) {
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));
}
@Override
public void onRequestPermissionsResult(int requestCode,String permissions[], int[] grantResults) {
Log.i("inside","callback");
switch (requestCode) {
case 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
Log.i("permission", "done");
} 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
}
}
@TargetApi(Build.VERSION_CODES.M)
private void updateMaps(){
String locationPermission = Manifest.permission.ACCESS_FINE_LOCATION;
int hasPermission = ContextCompat.checkSelfPermission(this,locationPermission);
String[] permissions = new String[] { locationPermission };
if (hasPermission != PackageManager.PERMISSION_GRANTED) {
requestPermissions(permissions, REQUEST_LOCATION);
}
else {
// Phew - we already have permission!
mMap.setMyLocationEnabled(true);
Log.i("clicked", "here");
// Access to the location has been granted to the app.
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if (mLastLocation != null) {
latitude = mLastLocation.getLatitude();
longitude = mLastLocation.getLongitude();
Log.i("latitude", "" + latitude);
Log.i("longitude", "" + longitude);
LatLng sydney = new LatLng(latitude, longitude);
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
Log.i("latitude", "" + latitude);
Log.i("longitude", "" + longitude);
}
}
@Override
public void onConnected(@Nullable Bundle bundle) {
Log.i("Connection", "OK");
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Log.i("Connection", "FAILED");
}
}
活动布局:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.marcocreation.******.Maps">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_maps" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
包含的活动:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.marcocreation.******.Maps"
tools:showIn="@layout/activity_maps">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.marcocreation.******.createMatch" />
</RelativeLayout>
很抱歉,如果我写了愚蠢的东西,三天我疯狂地使用地图,我编辑了很多时间。我的想法是当我点击右/下按钮相机时移动用户位置。
但没有改变