我正在尝试在我的模拟器和设备上加载mapview
我已经尝试了两天,但有时我只是得到了网格线没有任何地图,有时一个致命的错误,我的应用程序不能在我的模拟器和设备上启动。
我尝试了所有的方法,所有的代码都在互联网上,但都不起作用。你是我最后的希望。
我遵循了site上的步骤
我从here拿到了我的应用编程接口密钥
我已经尽我所能了。请告诉我,如果这个过程是不正确的,那么我应该怎么做。我是为姜饼2.3.3 (API 10)这样做的。
等待答案谢谢。
我的日志猫: 07-06 02:12:45.692: E/AndroidRuntime(3020):java.lang.RuntimeException:无法启动activity ComponentInfo{com.example.maps/com.example.maps.MainActivity}:android.view.InflateException:二进制XML文件第2行:膨胀类片段时出错
我的AndroidMenifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.maps"
android:versionCode="1"
android:versionName="1.0" >
<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"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".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="AEdPqrEAAAAI5QAuDgiTRjyU-y_MK-ZRQqBaN_VoLb4gADuCwA"/>
</application>
我的Main.xml
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
xmlns:tools="http://schemas.android.com/tools" />
我的MainActivity.Java
package com.example.maps;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import android.os.Bundle;
public class MainActivity extends MapActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MapView view = (MapView) findViewById(R.id.map);
view.setBuiltInZoomControls(true);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
发布于 2013-07-06 23:14:09
在main.xml中
不应该
android:name="com.google.android.gms.maps.MapFragment"
be
class="com.google.android.gms.maps.MapFragment"
发布于 2013-07-06 23:28:55
嗯,您正在使用片段,但将其加载到MapView中。这就是获取RuntimeException的原因,因为不可能将片段膨胀为MapView对象。MapView是android map API版本1中支持的一个旧类,该版本现在已被弃用。
从您引用的开发站点:
注意: Google Maps Android API v2使用了一种新的密钥管理系统。来自Google Maps Android应用程序(通常称为MapView )的现有密钥将不能与v2 v1一起使用。
您的活动实际上应该扩展MapFragment,并且应该使用FragmentManager或SupportFragmentManager来扩展您的地图。
public class MyActivity extends FragmentActivity {
private GoogleMap mMapView;
private SupportMapFragment mFragment;
@Override
protected void onCreate() {
super.onCreate();
FragmentManager fragmentManager = getSupportFragmentManager();
mFragment = ((SupportMapFragment) fragmentManager.findFragmentById(R.id.map));
mMapView = mFragment.getMap();
mMapView.getUiSettings().setZoomControlsEnabled(true);
// configure other settings of map view
}
}
另外,布局xml中的类名也应该是SupportMapFragment,如下所示:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
xmlns:tools="http://schemas.android.com/tools" />
你可以在这里找到更多信息:https://developers.google.com/maps/documentation/android/intro
https://stackoverflow.com/questions/17503096
复制相似问题