我有一个应用程序,它使用google play servises和google map。
当我从eclipse上传它时,地图有效,并且lastKnownLocation正确。
但是当我导出签名的apk时,地图不起作用。
为什么会这样?
这是我的代码:
public class NavigationActivity extends FragmentActivity implements LocationSource, LocationListener, OnMyLocationChangeListener {
private OnLocationChangedListener mListener;
private LocationManager lManager;
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setContentView(R.layout.activity_navigation);
lManager = (LocationManager)getSystemService(LOCATION_SERVICE);
lManager.requestLocationUpdates(lManager.getBestProvider(new Criteria(), true), 1, 1000, this);
setUpMapIfNeeded();
}
private void setUpMapIfNeeded(){
if (mMap == null) {
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setMyLocationButtonEnabled(false);
mMap.setOnMyLocationChangeListener(this);
CameraPosition camPos = new CameraPosition(new LatLng(50.088785,14.418675), 15, 60, 0);
mMap.moveCamera(CameraUpdateFactory.newCameraPosition(camPos));
}
}
public void activate(OnLocationChangedListener listener){mListener = listener;}
public void deactivate(){mListener = null;}
public void onLocationChanged(Location location){
if(mListener != null){
mListener.onLocationChanged(location);
}
}
public void onMyLocationChange(Location location){
if(mListener != null){
mListener.onLocationChanged(location);
}
}
@Override
protected void onResume(){
super.onResume();
setUpMapIfNeeded();
if(lManager != null){
lManager.requestLocationUpdates(lManager.getBestProvider(new Criteria(), true), 1, 1000, this);
}
}
@Override
protected void onPause(){
if(lManager != null){
lManager.removeUpdates(this);
}
super.onPause();
}
@Override
public void onProviderDisabled(String provider){}
@Override
public void onProviderEnabled(String provider){}
@Override
public void onStatusChanged(String provider, int status, Bundle extras){}
@Override
public boolean onCreateOptionsMenu(Menu menu){
getMenuInflater().inflate(R.menu.navigation, menu);
return true;
}
public void onStop(){
super.onStop();
EasyTracker.getInstance(this).activityStop(this);
}
}
答案 0 :(得分:2)
导出已签名的apk时,程序包的签名会发生变化,用于通过Google对您的应用进行身份验证。您必须使用已签名的apk的签名生成新的API密钥。
答案 1 :(得分:0)
请检查您的api密钥,它应该来自您自己的密钥。同时按照http://goo.gl/dvs0yo生成密钥。