【问题标题】:google map showing blank in genymotion谷歌地图在genymotion中显示空白
【发布时间】:2013-09-20 00:24:54
【问题描述】:

我正在使用 Google Nexus 4.2.2 - 在 Genymotion 上使用 Google API。谷歌地图片段是空的。我已经注册了 API 并在清单文件中提供了密钥。感谢您的帮助。

布局:

<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=".MapsTestActivity" >

    <fragment
       android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"/>

</RelativeLayout>

活动:

package com.chaseit.activities;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;

import com.chaseit.R;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsTestActivity extends Activity {

    static final LatLng HAMBURG = new LatLng(53.558, 9.927);
    static final LatLng KIEL = new LatLng(53.551, 9.993);
    private GoogleMap map;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps_test);
        // setupMap();
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        setupMap();
        super.onResume();
    }

    private void setupMap() {

        GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(
                R.id.map)).getMap();

        Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
                .title("Hamburg"));
        Marker kiel = map.addMarker(new MarkerOptions()
                .position(KIEL)
                .title("Kiel")
                .snippet("Kiel is cool")
                .icon(BitmapDescriptorFactory
                        .fromResource(R.drawable.ic_launcher)));

        // Move the camera instantly to hamburg with a zoom of 15.
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));

        // Zoom in, animating the camera.
        map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.maps_test, menu);
        return true;
    }

}

我从http://www.vogella.com/articles/AndroidGoogleMaps/article.html得到了示例代码

【问题讨论】:

  • 您使用的是什么类型的 Genymotion 设备?是支持 Google Play 服务的吗?

标签: android google-maps-android-api-2 genymotion


【解决方案1】:

为了在我们的 android 应用程序中使用 google maps v2,必须使用 google-play-services 库。此库仅在传递上下文以检查服务是否可用于该设备时才有效。在你的 oncreate 中添加这一行

GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());

评论我的结果

【讨论】:

  • 同样的结果。我得到一张空地图。
  • 你是否提供了在安卓中使用地图所需的所有权限和 api 密钥
  • 在 android androidfordevelopers-naresh.blogspot.in/2013/09/…987654321@ 中使用这个 url 关于授予权限和显示地图
  • 谢谢大家。 api密钥是问题所在。我再次复制粘贴,它现在可以工作了。
【解决方案2】:

检查输出日志,在地图上搜索,看看是否出现警告通知。就我而言,我发现:

09:03:34.197 E/Google Maps Android API( 7012): Authorization failure.  Please see https://developers.google.com/maps/documentation/android-api/start for how to correctly set up the map.
03-22 09:03:34.198 E/Google Maps Android API( 7012): In the Google Developer Console (https://console.developers.google.com)
03-22 09:03:34.198 E/Google Maps Android API( 7012): Ensure that the "Google Maps Android API v2" is enabled.
03-22 09:03:34.198 E/Google Maps Android API( 7012): Ensure that the following Android Key exists:

仔细检查以下内容:

  • 您在 Google 开发者控制台中为您的应用程序提供了正确的 SHA1 指纹(对我来说,这发生了某种变化)
  • 您提供了正确的包名称
  • 您在清单文件中包含了他们的 API 密钥(很明显,是的,我知道)
  • 在清单中也设置了适当的权限 ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION ACCESS_LOCATION_EXTRA_COMMANDS ACCESS_MOCK_LOCATION

  • 如果使用模拟器,请确保已安装 Google Play 服务(包括地图)。

更多详细路线请见here

【讨论】:

    【解决方案3】:

    在我的情况下,我没有找到解决方案,地图打开时是空白的,导航地图什么也没做,但是我有一个PlaceAutocompleteFragment,当我用它来搜索一个地方时,我移动了地图到那个地方并且它工作,地图现在显示并且您可以导航它。 您不必使用PlaceAutocompleteFragment,您可以通过在地图加载时将相机移动到您想要的位置然后从那里导航来解决问题,这可以通过将其添加到onMapReady() 函数来完成:

    LatLng latLng = new LatLng(15.501501,32.4325101) ;// change to the value you want
    float zoom = 15.0f;
    mapfragment.getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, zoom));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-03
      • 2013-09-07
      相关资源
      最近更新 更多