我完全按照这里给出的步骤。API 密钥是通过以下步骤获得的这里 我已经上传了市场上的 apk 用于测试目的,但它仍然没有显示地图,尽管它显示带有调试密钥的地图。但是当我尝试使用发布谷歌地图密钥时,它显示带有放大和缩小的白屏按钮,但没有地图。
地图片段
public class CustomMap extends SupportMapFragment {
private static final int ZOOMIN_ANIMATION_DURATION = 300;
public static CustomMap newInstance() {
Bundle bundle = new Bundle();
CustomMap customMap = new CustomMap();
customMap.setArguments(bundle);
return customMap;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
@Override
public void onResume() {
super.onResume();
GoogleMap googleMap = getMap();
if (googleMap == null) {
} else {
LatLng mLatLng = new LatLng(70.00,
33.00);
googleMap.addMarker(new MarkerOptions()
.title("Title")
.snippet("Address")
.position(mLatLng)
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(mLatLng));
googleMap.animateCamera(CameraUpdateFactory.zoomBy(10),
ZOOMIN_ANIMATION_DURATION, null);
}
}
}
主要活动
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<fragment
android:id="@+id/fragment1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
class="com.example.maptest.CustomMap"
/>
</RelativeLayout>
显现
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="com.baresso.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" >
</uses-permission>
<uses-permission android:name="com.baresso.permission.MAPS_RECEIVE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.maptest.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="AIzaSyDcAy3bEVhv_lhAH1hHNHk_RpvyXiN0xNI" />
</application>
</manifest>