【发布时间】:2019-04-05 18:42:24
【问题描述】:
Google 地图活动在发布模式下不工作,但在调试模式下工作正常。
尝试了与我的查询相关的堆栈溢出的所有内容,但它不起作用。
我还使用“keytool -list -v -keystore mystore.keystore”从 cmd 提示符复制了 SHA1 密钥并将其粘贴到谷歌控制台中,但仍然无法正常工作。
在调试模式下一切正常.. 我还授予了 android marshmallow 及更高版本的运行时权限。
注意事项: 我已经使用 mapView 代替片段.. 我也尝试过使用地图片段,但仍然是同样的问题。
activity_maps.xml
<com.google.android.gms.maps.MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent" />
你可以在这里看到区别:
In debug mode, In release mode
分级:
implementation 'com.google.android.gms:play-services-maps:16.1.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<permission android:name="com.example.mapsact.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
<uses-permission android:name="com.example.mapsact.permission.MAPS_RECEIVE" />
MapsActivity.java
MapView mMapView;
GoogleMap mMap;
LocationManager location;
@Override
public void onResume() {
super.onResume();
try {
locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 20, 1, (android.location.LocationListener) this);
} catch (SecurityException e) {
e.printStackTrace();
}
mMapView.onResume();
//ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
}
@Override
public void onLocationChanged(Location location) {
// Getting latitude of the current location
latitude = location.getLatitude();
// Getting longitude of the current location
longitude = location.getLongitude();
// Creating a LatLng object for the current location
LatLng latLng = new LatLng(latitude, longitude);
//now = mMap.addMarker(new MarkerOptions().position(latLng).title("Location").snippet("Current"));
// Showing the current location in Google Map
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(15.0f));
if(isNetworkConnected()) {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("mobile", mobile);
jsonObject.put("lati", latitude);
jsonObject.put("longi", longitude);
SendLoc sendloc = new SendLoc();
sendloc.execute(jsonObject.toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
else {
Toast.makeText(this,"No Internet Connectivity",Toast.LENGTH_LONG).show();
}
}
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.animateCamera(CameraUpdateFactory.zoomTo(15.0f));
mMap.setMyLocationEnabled(true);
}
【问题讨论】:
标签: android