朋友您好我想在我的Android设备上显示地图,所以我的代码如下
main.xml中
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="400dp"
android:layout_height="400dp"
/>
的Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pakagename.example"
android:versionCode="1"
android:versionName="1.0" >
<!-- android:versionCode="2" -->
<!-- android:versionName="1.1" > -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<permission
android:name="com.pakagename.example.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.pakagename.example.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<supports-screens
android:anyDensity="false"
android:largeScreens="true"
android:normalScreens="false"
android:resizeable="false"
android:smallScreens="false"
android:xlargeScreens="true" />
<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" />
<!--
The following two permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:name=".RestaurantApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="MY_API_KEY"
/>
<activity
android:name="pkg.android.rootways.restaurantapp.SplashActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:windowSoftInputMode="adjustPan" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="pkg.android.rootways.restaurantapp.ReviewActivity"
android:screenOrientation="landscape"
android:windowSoftInputMode="adjustPan" />
</application>
</manifest>
ReviewActivity.java
public class ReviewActivity extends FragmentActivity implements LocationListener
{
@Override
protected void onCreate(Bundle savedInstanceState) {
GoogleMap myMap;
super.onCreate(savedInstanceState);
setContentView(R.layout.res_review);
initMap();
}
public void initMap() {
FragmentManager myFragmentManager = getSupportFragmentManager();
SupportMapFragment mySupportMapFragment = (SupportMapFragment) myFragmentManager
.findFragmentById(R.id.map);
myMap = mySupportMapFragment.getMap();
if (myMap != null)
{
System.out.println("MAp");
myMap.setMyLocationEnabled(true);
myMap.getUiSettings().setZoomControlsEnabled(true);
myMap.getUiSettings().setCompassEnabled(true);
myMap.getUiSettings().setMyLocationButtonEnabled(true);
myMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
else
{
System.out.println("Null Value");
}
}
}
当我运行ablove代码时,它给了我像
这样的错误 12-02 16:23:55.544: E/AndroidRuntime(25420): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4030500 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
12-02 16:23:55.544: E/AndroidRuntime(25420): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
12-02 16:23:55.544: E/AndroidRuntime(25420): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
12-02 16:23:55.544: E/AndroidRuntime(25420): at com.google.android.gms.maps.internal.q.v(Unknown Source)
12-02 16:23:55.544: E/AndroidRuntime(25420): at com.google.android.gms.maps.internal.q.u(Unknown Source)
12-02 16:23:55.544: E/AndroidRuntime(25420): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
12-02 16:23:55.544: E/AndroidRuntime(25420): at com.google.android.gms.maps.SupportMapFragment$b.cE(Unknown Source)
12-02 16:23:55.544: E/AndroidRuntime(25420): at com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
12-02 16:23:55.544: E/AndroidRuntime(25420): at com.google.android.gms.dynamic.a.a(Unknown Source)
12-02 16:23:55.544: E/AndroidRuntime(25420): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
12-02 16:23:55.544: E/AndroidRuntime(25420): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
12-02 16:23:55.544: E/AndroidRuntime(25420): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:284)
12-02 16:23:55.544: E/AndroidRuntime(25420): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
12-02 16:23:55.544: E/AndroidRuntime(25420):
任何想法我该如何解决?
答案 0 :(得分:3)
我解决了isssus
map api key中的问题我创建第一个api密钥但它不是runnig然后我为同一个pakagename创建第二个api密钥所以有两个api密钥用于相同的pakage之前它可能会冲突密钥所以我做出像我创建的解决方案带有新pakage名称的新api密钥,它正在为我工作
答案 1 :(得分:2)
在清单文件中添加:
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
同时检查:Google Maps V2
希望这有帮助。