【问题标题】:Android map not showing安卓地图不显示
【发布时间】:2013-11-13 17:21:30
【问题描述】:

我有一个应用,它使用 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);
}
}

【问题讨论】:

  • 你有签名版本的密钥吗?

标签: android google-maps google-maps-android-api-2 google-play-services


【解决方案1】:

当您导出已签名的 apk 时,包的签名会发生变化,该签名用于通过 Google 对您的应用进行身份验证。您必须使用已签名 apk 的签名生成新的 API 密钥。

【讨论】:

  • 非常感谢。从导出签名的应用程序窗口中获得了 SHA1,现在地图可以工作了。谢谢!
【解决方案2】:

请检查您的 api 密钥,它应该是由您自己的密钥生成的。同样关注http://goo.gl/dvs0yo生成密钥。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多