我在我的Android應用程序中添加了一個mapview。我在清單中使用了正確的設置,現在我正面臨一個問題。當我去到我有地圖的地方時,它只顯示畫布而不顯示地圖。如果我觸摸它只會開始加載。即使那樣它也沒有完全加載,只加載到一定的水平。如果我繼續觸摸它連續加載的屏幕。但即使如此,我無法放大或縮小,甚至無法移動地圖。有沒有解決方案?我做錯了什麼?Android MapView不加載,除非你在地圖上觸摸
我的代碼
MapView mapView;
GoogleMap map;
mapView = (MapView)view.findViewById(R.id.map);
Bundle savedInstanceState = null;
mapView.onCreate(savedInstanceState);
// Gets to GoogleMap from the MapView and does initialization stuff
map = mapView.getMap();
map.getUiSettings().setMyLocationButtonEnabled(false);
map.setMyLocationEnabled(true);
MapsInitializer.initialize(activity);
double lat;
double lon;
lat = Double.parseDouble(theaterDetail.getLatitude());
lon = Double.parseDouble(theaterDetail.getLongitude());
// Updates the location and zoom of the MapView
map.addMarker(new MarkerOptions().position(
new LatLng(lat, lon)).title(theaterDetail.getAddress()));
final LatLng THEATER_POSITION = new LatLng(lat, lon);
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(THEATER_POSITION) // Sets the center of the map to
// THEATER_POSITION
.zoom(10) // Sets the zoom
.bearing(360) // Sets the orientation of the camera to east
.tilt(30) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
map.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
XML
<com.google.android.gms.maps.MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
清單
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.***.***"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<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-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"
/>
<permission
android:name="com.***.***.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.***.***.permission.MAPS_RECEIVE" />
<application
android:name="com.***.***.service.CommonVariable"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppBaseTheme"
android:hardwareAccelerated="true" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<!-- <uses-library android:name="com.google.android.maps" /> -->
<activity
android:name="com.***.***.MainActivity"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock.Light.DarkActionBar"
android:windowSoftInputMode="adjustPan"
android:hardwareAccelerated="true">
</activity>
<activity
android:name="com.***.***.Map"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock.Light.DarkActionBar" ></activity>
<activity
android:name="com.***.***.WelcomeActivity"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock.NoActionBar"
android:hardwareAccelerated="true" >
<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="*********************" />
</application>
</manifest>
上面的代碼在java類中,您正在寫哪些函數?以及爲什麼你要調用這個函數mapView.onCreate(savedInstanceState);? – EagleEye
我的mapview代碼被放置在一個asyncTask中,我就這樣調用它。 \t \t如果(頁面== Element.THEATER_DETAIL.getType()){ \t \t \t視圖= inflater.inflate(R.layout.filmhall,容器,FALSE); \t \t \t Theatre theater =(Theatre)item.get(position); \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t新的背景((theater.getTheaterId()),視圖).execute(); \t \t \t \t \t} – CraZyDroiD
@EagleEye你有解決方案嗎? – CraZyDroiD