【发布时间】:2015-01-12 05:13:50
【问题描述】:
我在我的 android 应用程序中添加了一个地图视图。我在清单中使用了正确的设置,现在我遇到了一个问题。当我去有我的地图的地方时,它只显示画布而不显示地图。如果我触摸它,它只会开始加载。即使那样它也没有完全加载。它只加载到一定的水平。如果我一直触摸屏幕,它会不断加载。但即便如此,我也无法放大或缩小,甚至无法移动地图。有解决方案吗?我是不是做错了什么?
我的代码
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);?
-
我的 mapview 代码放在 asyncTask 中,我这样称呼它。 if (page == Element.THEATER_DETAIL.getType()) { view = inflater.inflate(R.layout.filmhall, container, false);剧院剧院 = (剧院) item.get(位置);新背景((剧院.getTheaterId()),视图)。执行(); }
-
@EagleEye 你有解决办法吗?
-
你能移动这段代码吗 mapView = (MapView)view.findViewById(R.id.map);捆绑 savedInstanceState = null; mapView.onCreate(savedInstanceState); // 从 MapView 获取 GoogleMap 并进行初始化 map = mapView.getMap(); map.getUiSettings().setMyLocationButtonEnabled(false); map.setMyLocationEnabled(true);到 onPreExecute() 并检查?
-
只需添加 mapView.onResume() - 我花了大约 5 个小时才发现 =)
标签: android google-maps android-mapview