目前我正在研究谷歌地图,为了创建它,我遵循了 android 开发者网站中的所有说明。但我无法在我的设备中加载地图,但我可以指向各个地方。我的设备是否支持 Google API V2?有什么方法可以在我的设备上查看地图吗?我的设备版本是 2.3.3。
问问题
1184 次
1 回答
1
我有一个有效的 GoogleMaps v2 应用程序,最初我遇到了与您描述的相同的问题。我的问题是我使用的 API 密钥与我用来签署应用程序的证书不匹配(开发阶段的调试/开发和 Play 发布的应用程序的发布)。该应用程序适用于 10 及更高版本的所有 Android 版本(因此它适用于 2.3.3)。从日志错误中可以看出您可能遇到了连接问题。您是否声明了适当的使用权限?它应该是:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
这是主地图代码的简短片段:
public class LocationActivity extends MapActivity {
private MapController mapController;
private MapView mapView;
private LocationManager locationManager;
private MyLocationOverlay myLocationOverlay;
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
if(Utils.isRelease(getApplicationContext())) {
setContentView(R.layout.location_activity_release); // bind the layout to the activity
} else {
setContentView(R.layout.location_activity); // bind the layout to the activity
}
// Configure the Map
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(false);
mapController = mapView.getController();
mapController.setZoom(15); // Zoon 1 is world view
myLocationOverlay = new MyLocationOverlay(this, mapView);
mapView.getOverlays().add(myLocationOverlay);
// More map configurations follow...
以及布局(注意地图 API 密钥的不同):location_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:apiKey="@string/google_maps_v1_api_key"
android:clickable="true" />
和(location_activity_release.xml):
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:apiKey="@string/google_maps_v1_api_key_release"
android:clickable="true" />
于 2013-07-23T08:21:45.643 回答