0

背景:

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

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

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

平台:我正在开发应用程序以在 Froyo 和更高版本上运行..但现在我只是想让它在 Froyo 上运行。

密钥:我创建了一个启用了以下服务的密钥:“Google Maps Android API v2”和“Places API”已打开。

这是完整的 LogCat。注意:LogCat 以无穷无尽的“无法联系 Google 服务器”结尾,所以我用这些消息中的最后 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);
    }

根据调试器结果,通过意图传入的额外值似乎都存在且正确。

这是地图布局的 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>  

不知道为什么地图没有显示。想法?

4

1 回答 1

0

缺少以下权限:

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

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

于 2013-04-03T17:44:12.540 回答