无法在模拟器中执行 MAP API
MainActivity.java
public class MainActivity extends FragmentActivity {
// Google Map
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* function to load map. If map is not created it will create it for you
* */
private void initilizeMap() {
if (googleMap == null) {
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
googleMap = fm.getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
@Override
protected void onResume() {
super.onResume();
initilizeMap();
}
}
显现
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googlemaps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.googlemaps.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>
<!-- Goolge Maps API Key -->
<!-- <meta-data
android:name="com.example.googlemaps.API_KEY"
android:value="AIzaSyB_nfzBC625kv_O6GzW-O8l2oLBhqAGCIc" /> -->
<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyB_nfzBC625kv_O6GzW-O8l2oLBhqAGCIc"/>
</application>
</manifest>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
没有错误....但日志如下所示
10-17 11:58:50.169: D/dalvikvm(592): DexOpt: couldn't find field Landroid/content/res/Configuration;.smallestScreenWidthDp
10-17 11:58:50.169: W/dalvikvm(592): VFY: unable to resolve instance field 28
10-17 11:58:50.169: D/dalvikvm(592): VFY: replacing opcode 0x52 at 0x0012
10-17 11:58:50.199: W/GooglePlayServicesUtil(592): Google Play Store is missing.
10-17 11:58:50.209: W/GooglePlayServicesUtil(592): Google Play Store is missing.
10-17 11:58:50.209: W/GooglePlayServicesUtil(592): Google Play Store is missing.
10-17 11:58:50.219: W/GooglePlayServicesUtil(592): Google Play Store is missing.
10-17 11:58:50.219: W/GooglePlayServicesUtil(592): Google Play Store is missing.
10-17 11:58:50.259: W/GooglePlayServicesUtil(592): Google Play Store is missing.
10-17 11:58:50.369: W/GooglePlayServicesUtil(592): Google Play Store is missing.
10-17 11:58:50.399: W/GooglePlayServicesUtil(592): Google Play Store is missing.
10-17 11:58:50.459: V/TLINE(592): new: android.text.TextLine@4090edb0
10-17 11:58:50.499: D/dalvikvm(592): GC_CONCURRENT freed 80K, 3% free 9051K/9287K, paused 7ms+5ms
10-17 11:58:50.759: V/TLINE(592): new: android.text.TextLine@408a52c0
我已添加 Google Play 商店
我得到的模拟器如下
不能在模拟器中运行 MAP-API
如果是这样,是否有任何替代方法可以让我的程序在 MAP 的模拟器中执行