我試圖表現出google map
在我的應用程序,但它顯示的小方塊盒屏幕,而不是google maps
谷歌地圖是不是沃金
這裏是我的Mainactivity
public class MainActivity extends FragmentActivity {
private static final int GPS_ERRORDIALOG_REQUEST = 9001;
GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (servicesOK()) {
//Toast.makeText(this, "Google play services successfully connected.", Toast.LENGTH_SHORT).show();
setContentView(R.layout.activity_map);
}else{
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;
}
public boolean servicesOK(){
int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (isAvailable == ConnectionResult.SUCCESS) {
return true;
}else if (GooglePlayServicesUtil.isUserRecoverableError(isAvailable)) {
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST);
dialog.show();
}else{
Toast.makeText(this, "Can't connect to google play services.", Toast.LENGTH_SHORT).show();
}
return false;
}
我activiy_map.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
我的mainfest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gmapapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<permission
android:name="com.example.gmapapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.gmapapp.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission
android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<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.example.gmapapp.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.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="API_KEY"/>
</application>
</manifest>
我logcat
11-30 15:23:13.430: E/dalvikvm(6948): GC_CONCURRENT freed 1785K, 24% free 7739K/10147K, paused 3ms+12ms
11-30 15:27:45.260: E/dalvikvm(6948): GC_CONCURRENT freed 1673K, 24% free 7781K/10147K, paused 3ms+4ms
11-30 15:30:40.500: E/dalvikvm(7048): GC_CONCURRENT freed 1007K, 18% free 7301K/8803K, paused 2ms+3ms
11-30 15:30:40.840: E/dalvikvm(7048): GC_FOR_ALLOC freed 856K, 23% free 7424K/9571K, paused 2ms+5ms
11-30 15:30:41.040: E/dalvikvm(7048): GC_FOR_ALLOC freed 842K, 23% free 7460K/9571K, paused 2ms+4ms
日誌貓請? –
您是否獲得了此應用程序的api密鑰? –
@JiteshUpadhyay我已更新我的問題。 – FAISAL