无法在Android应用程序中显示地图



背景:

应用概述:我正在开发一款Android应用程序,该应用程序将在列表视图中显示地点列表,然后当用户单击列表视图屏幕上的按钮时,最终允许用户在谷歌地图上显示这些地点(使用谷歌地图v2 API(。此时此刻,我只是想在列表视图中显示地点列表,并简单地显示我当前位置的地图,并用一个标记显示我的位置。

当前状态:到目前为止,该应用程序正确地显示了带有位置的列表视图,但当单击按钮显示地图时,我会看到一个显示Zoom控件的空白屏幕。下面是LogCat。我相信关键错误信息如下:

04-03 09:52:24.295:E/Google地图Android API(1896(:加载地图失败。无法联系谷歌服务器。

平台:我正在开发应用程序,以便在Froyo及以后运行。。但现在我只是想让这个在Froyo上运行。

密钥:我已经创建了一个密钥,并启用了以下服务:"谷歌地图Android API v2"one_answers"Places API"已打开。

这是完整的LogCat。注意:LogCat以无尽的"无法联系谷歌服务器"结束,所以我用最后3条消息将其切断。

04-03 09:42:17.447: D/Your Location(1896): latitude:32.91296010000001, longitude: -117.17031355
04-03 09:42:36.577: D/dalvikvm(1896): threadid=1: still suspended after undo (sc=1 dc=1 s=Y)
04-03 09:42:36.577: D/dalvikvm(1896): GC_FOR_MALLOC freed 6014 objects / 359192 bytes in 82ms
04-03 09:42:39.467: D/Places Status(1896): OK
04-03 09:43:53.437: D/dalvikvm(1896): GC_FOR_MALLOC freed 7413 objects / 369560 bytes in 226ms
04-03 09:43:54.537: D/dalvikvm(1896): DexOpt: couldn't find field Landroid/content/res/Configuration;.smallestScreenWidthDp
04-03 09:43:54.537: W/dalvikvm(1896): VFY: unable to resolve instance field 23
04-03 09:43:54.537: D/dalvikvm(1896): VFY: replacing opcode 0x52 at 0x0012
04-03 09:43:54.537: D/dalvikvm(1896): VFY: dead code 0x0014-0018 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.b (Landroid/content/res/Resources;)Z
04-03 09:43:56.117: D/dalvikvm(1896): GC_FOR_MALLOC freed 3000 objects / 314664 bytes in 84ms
04-03 09:43:56.307: W/dalvikvm(1896): Unable to resolve superclass of Lmaps/p/s; (425)
04-03 09:43:56.307: W/dalvikvm(1896): Link of class 'Lmaps/p/s;' failed
04-03 09:43:56.307: W/dalvikvm(1896): Unable to resolve superclass of Lmaps/y/bo; (3818)
04-03 09:43:56.307: W/dalvikvm(1896): Link of class 'Lmaps/y/bo;' failed
04-03 09:43:56.307: W/dalvikvm(1896): Unable to resolve superclass of Lmaps/i/k; (4206)
04-03 09:43:56.307: W/dalvikvm(1896): Link of class 'Lmaps/i/k;' failed
04-03 09:43:56.317: E/dalvikvm(1896): Could not find class 'maps.i.k', referenced from method maps.z.ag.a
04-03 09:43:56.317: W/dalvikvm(1896): VFY: unable to resolve new-instance 3538 (Lmaps/i/k;) in Lmaps/z/ag;
04-03 09:43:56.317: D/dalvikvm(1896): VFY: replacing opcode 0x22 at 0x006d
04-03 09:43:56.397: D/dalvikvm(1896): VFY: dead code 0x006f-007f in Lmaps/z/ag;.a (Landroid/view/LayoutInflater;Lcom/google/android/gms/maps/GoogleMapOptions;ZLjava/lang/String;)Lmaps/z/ag;
04-03 09:43:57.727: D/dalvikvm(1896): GC_FOR_MALLOC freed 4941 objects / 398416 bytes in 102ms
04-03 09:43:58.367: E/Google Maps Android API(1896): Failed to load map.  Could not contact Google servers.
04-03 09:51:41.015: D/dalvikvm(1896): GC_FOR_MALLOC freed 5101 objects / 340064 bytes in 97ms
04-03 09:52:24.295: E/Google Maps Android API(1896): Failed to load map.  Could not contact Google servers.
04-03 09:53:33.888: D/dalvikvm(1896): GC_EXTERNAL_ALLOC freed 1948 objects / 134008 bytes in 260ms
04-03 09:57:34.449: E/Google Maps Android API(1896): Failed to load map.  Could not contact Google servers.
04-03 09:57:34.649: D/libEGL(1896): loaded /system/lib/egl/libGLES_android.so
04-03 09:57:34.679: D/libEGL(1896): loaded /system/lib/egl/libEGL_adreno200.so
04-03 09:57:34.869: D/libEGL(1896): loaded /system/lib/egl/libGLESv1_CM_adreno200.so
04-03 09:57:34.879: D/libEGL(1896): loaded /system/lib/egl/libGLESv2_adreno200.so
04-03 09:57:35.009: E/Google Maps Android API(1896): Failed to load map.  Could not contact Google servers.
04-03 09:57:35.109: E/Google Maps Android API(1896): Failed to load map.  Could not contact Google servers.
04-03 09:57:35.199: E/Google Maps Android API(1896): Failed to load map.  Could not contact Google servers.

负责显示地图的代码如下:

public class PlacesMapActivity extends FragmentActivity { 
 // Nearest places
PlacesList nearPlaces;  
private SupportMapFragment mMapFragment;
LatLng latLng;

double latitude;
double longitude;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map_places);
    // Getting intent data
    Intent i = getIntent();
    // Users current geo location
    String user_latitude = i.getStringExtra("user_latitude");
    String user_longitude = i.getStringExtra("user_longitude");
    latLng = new LatLng(Double.parseDouble(user_latitude), Double.parseDouble(user_longitude));
    // Nearplaces list
    nearPlaces = (PlacesList) i.getSerializableExtra("near_places");

    final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    // Try to obtain the map from the SupportMapFragment.
    mMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
       // Not found so make a new instance and add it to the transaction for swapping
    if (mMapFragment == null) {
        mMapFragment = SupportMapFragment.newInstance();
        ft.add(R.id.map, mMapFragment);
    }
    ft.commit();
    }
        @Override
    public void onAttachedToWindow() {
    // Load the map here such that the fragment has a chance to completely load or else the GoogleMap value may be null
    GoogleMap googleMap;
    googleMap = (mMapFragment).getMap();    
    googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    googleMap.addMarker(new MarkerOptions()
            .position(latLng)
            .title("My Spot")
            .snippet("This is my spot!")
            .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
    googleMap.getUiSettings().setCompassEnabled(true);
    googleMap.getUiSettings().setZoomControlsEnabled(true);
    googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 10));
    super.onAttachedToWindow();
    }
        @Override
    public void onAttachFragment(Fragment fragment) {
        // TODO Auto-generated method stub
        super.onAttachFragment(fragment);
    }

根据调试器的结果,通过intent传递的额外值似乎都存在并且是正确的。

以下是地图布局的XML:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <fragment 
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"        
        class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>  

不确定为什么没有显示地图。想法?

缺少以下权限:

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>

一旦我添加了权限,我就可以看到地图了。

相关内容

  • 没有找到相关文章

最新更新