在此地图活动中,我得出了两个点的方向,但是当此活动加载时,显示警告,提示未找到googlecertificates类并断开了google api服务
MapActivity
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, View.OnClickListener, DirectionCallback {
private GoogleMap googleMap;
private Direction direction;
private String serverKey = "YOUR_API_KEY";
private Double destination_lat,destination_long;
private LatLng origin;
private Button direc;
private User u;
private LatLng destination;
private static final String TAG = "MapsActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
destination_lat= getIntent().getExtras().getDouble("Latitude");
destination_long= getIntent().getExtras().getDouble("Longtitude");
origin = new LatLng(37.424,-122.084);
destination = new LatLng(destination_lat,destination_long);
Log.d(TAG,""+origin+" "+destination);
direc = findViewById(R.id.direction);
direc.setOnClickListener(this);
((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMapAsync(this);
/*SupportMapFragment myMapFragment = new SupportMapFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.map,myMapFragment).commit();
try{
myMapFragment.getMapAsync(this);
}
catch (Exception e)
{
Log.d(TAG,e.toString());
}*/
}
@Override
public void onMapReady(GoogleMap googleMap) {
this.googleMap = googleMap;
// Add a marker in Sydney and move the camera
/* LatLng location = new LatLng(23.0225, 72.5714);
mMap.addMarker(new MarkerOptions().position(location).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(location));
location();*/
}
@Override
public void onClick(View v) {
int id = v.getId();
if (id == R.id.direction) {
location();
}
}
private void location()
{
Snackbar.make(direc, "Direction Requesting...", Snackbar.LENGTH_SHORT).show();
GoogleDirection.withServerKey(serverKey)
.from(origin)
.to(destination)
.transportMode(TransportMode.DRIVING)
.execute(this);
}
@Override
public void onDirectionSuccess(Direction direction, String rawBody)
{
Snackbar.make(direc, "Success with status : " + direction.getStatus(), Snackbar.LENGTH_SHORT).show();
if (direction.isOK()) {
Route route = direction.getRouteList().get(0);
googleMap.addMarker(new MarkerOptions().position(origin));
googleMap.addMarker(new MarkerOptions().position(destination));
ArrayList<LatLng> directionPositionList = route.getLegList().get(0).getDirectionPoint();
googleMap.addPolyline(DirectionConverter.createPolyline(this, directionPositionList, 5, Color.RED));
setCameraWithCoordinationBounds(route);
direc.setVisibility(View.GONE);
} else {
Snackbar.make(direc, direction.getStatus(), Snackbar.LENGTH_SHORT).show();
}
}
@Override
public void onDirectionFailure(Throwable t) {
Snackbar.make(direc, t.getMessage(), Snackbar.LENGTH_SHORT).show();
}
private void setCameraWithCoordinationBounds(Route route) {
LatLng southwest = route.getBound().getSouthwestCoordination().getCoordination();
LatLng northeast = route.getBound().getNortheastCoordination().getCoordination();
LatLngBounds bounds = new LatLngBounds(southwest, northeast);
googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));
}
}
清单
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.geofirecollection">
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="YOUR_API_KEY" />
<activity
android:name=".UI.MapsActivity"
android:label="@string/title_activity_maps"></activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity android:name=".UI.UserlistActivity" />
<activity android:name=".UI.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
应用程序级别Gradle
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
googleServices { disableVersionCheck = false }
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.geofirecollection"
minSdkVersion 26
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-firestore:17.1.2'
// implementation 'com.google.firebase:firebase-auth:16.0.5'
implementation 'com.google.firebase:firebase-storage:16.0.4'
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-database:16.0.4'
implementation 'uk.co.mgbramwell.geofire:geofire-android:0.0.2'
implementation 'com.google.android.gms:play-services-maps:16.1.0'
//implementation 'com.google.android.gms:play-services-location:16.0.2'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.android.support:recyclerview-v7:28.0.0-alpha3'
implementation 'com.android.support:cardview-v7:28.0.0-alpha3'
implementation 'com.xwray:groupie:2.1.0'
implementation 'com.squareup.picasso:picasso:2.71828'
//direction library
implementation 'com.akexorcist:googledirectionlibrary:1.1.1'
implementation 'com.google.firebase:firebase-auth:16.0.5'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:design:28.0.0'
}
当地图活动加载时,然后显示一些警告
W/DynamiteModule: Local module descriptor class for com.google.android.gms.googlecertificates not found.
I/DynamiteModule: Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:4
Selected remote version of com.google.android.gms.googlecertificates, version >= 4
W/zygote: Skipping duplicate class check due to unrecognized classloader
我的Google Play服务SDK已升级,我插入了正确的Google API密钥,但显示此警告,然后断开了Google API服务 请给个建议