我有一个应用程序,它使用谷歌播放服务和谷歌地图。
当我从 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);
}
}