地图适用于调试密钥。在使用签名密钥库生成新的api密钥后,使用此新版本的api密钥,地图就消失了。
这是我的步骤:
它出了什么问题?
这是清单xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wswsoft.mapdemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.wswsoft.mapdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="com.wswsoft.mapdemo.permission.MAPS_RECEIVE"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.wswsoft.mapdemo.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value=" AIzaSyD4hWWjxOV2zpM7hEJZK6pp4hmvBrN1AII"/>
</application>
</manifest>
这是布局xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<!-- body -->
<FrameLayout android:id="@+id/map_fragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/loc_topbar"
android:layout_above="@+id/loc_bottombar">
<!-- Put fragments dynamically -->
</FrameLayout>
<!-- bottom bar component -->
<ImageView
android:id="@+id/loc_bottombar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:src="@drawable/bottombar" />
<Button
android:id="@+id/locBtn"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_alignTop="@+id/loc_bottombar"
android:layout_alignParentLeft="true"
android:layout_marginTop="10dp"
android:background="@drawable/half_button"
android:text="定位"
android:textSize="20sp"/>
<Button
android:id="@+id/loc_nextBtn"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_alignTop="@+id/loc_bottombar"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:background="@drawable/half_button"
android:text="继续"
android:textSize="20sp"/>
<ImageView
android:id="@+id/nextImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/loc_nextBtn"
android:layout_alignTop="@+id/loc_nextBtn"
android:layout_marginRight="30dp"
android:layout_marginTop="5dp"
android:src="@drawable/next" />
<ImageView
android:id="@+id/locImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/locBtn"
android:layout_alignTop="@+id/locBtn"
android:layout_marginRight="30dp"
android:layout_marginTop="5dp"
android:src="@drawable/location" />
</RelativeLayout>
以下是活动代码:
package com.wswsoft.mapdemo;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Dialog;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class MainActivity extends FragmentActivity {
private static final String MAP_FRAGMENT_TAG = "map";
private GoogleMap mMap;
private SupportMapFragment mMapFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
// Showing status
if(status!=ConnectionResult.SUCCESS){ // Google Play Services are not available
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
dialog.show();
}else {
mMapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentByTag(MAP_FRAGMENT_TAG);
// We only create a fragment if it doesn't already exist.
if (mMapFragment == null) {
// To programmatically add the map, we first create a SupportMapFragment.
mMapFragment = SupportMapFragment.newInstance();
// Then we add it using a FragmentTransaction.
FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.map_fragment, mMapFragment, MAP_FRAGMENT_TAG);
fragmentTransaction.commit();
}
// We can't be guaranteed that the map is available because Google Play services might
// not be available.
setUpMapIfNeeded();
}
Button locBtn=(Button)findViewById(R.id.locBtn);
locBtn.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
showMap();
}
});
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the
// map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = mMapFragment.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
mMap.setMyLocationEnabled(true);
}
}
}
@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
// mLocationSource.onResume();
}
private void showMap()
{
// Check if we were successful in obtaining the map.
Location mLocation;
String sLong,sLat, sRange;
if (mMap != null) {
// The Map is verified. It is now safe to manipulate the map.
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
mMap.setMyLocationEnabled(true);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
// 高精度
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider = locationManager.getBestProvider(criteria, true);
mLocation = locationManager.getLastKnownLocation(provider);
mLocation=mMap.getMyLocation();
if (mLocation!=null)
{
sLat=Double.toString(mLocation.getLatitude());
sLong=Double.toString(mLocation.getLongitude());
sRange=Double.toString(mLocation.getAccuracy());
LatLng latLng = new LatLng(mLocation.getLatitude(), mLocation.getLongitude());
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(15));
Log.i("location:Longitude",sLat);
Log.i("location:Latitude",sLong);
Log.i("location:Range",sRange);
//locationManager.requestLocationUpdates(provider, 20000, 0, this);
}
}
}
}
答案 0 :(得分:0)
尝试
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyD4hWWjxOV2zpM7hEJZK6pp4hmvBrN1AII"/>
代替 android:value=" AIzaSyD4hWWjxOV2zpM7hEJZK6pp4hmvBrN1AII"
答案 1 :(得分:0)
删除以下行中的空格:
android:value=" AIzaSyD4hWWjxOV2zpM7hEJZK6pp4hmvBrN1AII"