2013-07-23 82 views
0

目前我正在Google地图上工作,并且为了创建我遵循android开发人员网站中的所有说明。但我不能在我的设备中加载地图,但我可以指出不同的地方和所有。我的设备是否支持Google API V2?有什么方法可以在我的设备上查看地图吗?我的设备版本是2.3.3。谷歌地图API v2不能在设备上工作

+0

您是否在不同的设备上测试您的应用程序? – TheFlash

+1

你可以在这里粘贴你的logcat吗? – RAAAAM

+0

07-23 13:01:18.726:E/MapActivity(2640):无法获取连接工厂的客户...... 我可以查看网格以及所有的点,但地图上没有加载 –

回答

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... 

而且布局(请注意在Maps 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" /> 
+0

如何获得在V1的API密钥?我不和我拥有它,只是有V2 API密钥。 –

+0

你在项目中使用“google_maps_v1_api_key”?有没有办法用在V2 API密钥来检查应用程序有更低版本的设备? –