草庐IT

关于 android:MapView google maps api V2 看起来是空白的,只显示带有 /- 按钮的网格

codeneng 2023-03-28 原文

MapView google maps api V2 looks blank only display grid with +/- button

我完成了所有步骤,我将 google-play-sevices 添加到我的项目中,我做了所有事情。我不知道有什么问题。我使用调试证书指纹使用 SHA1 指纹创建我的 api 密钥在 Eclipse 窗口>首选项>android;我正在使用 lg E400 con android 2.3.6

主活动:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import android.os.Bundle;
import android.app.Activity;


import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.MapsInitializer;

public class MainActivity extends Activity {
  GoogleMap map;
  MapView m;
  com.google.android.gms.maps.Projection projection;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);
     m=(MapView) findViewById(R.id.mapview);
    m.onCreate(savedInstanceState);
    map = m.getMap();
    if (map != null) {
        // The Map is verified. It is now safe to manipulate the map.

    }else{
        // check if google play service in the device is not available or out-dated.
        GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);

        // nothing anymore, cuz android will take care of the rest (to remind user to update google play service).
    }

    try{map.getUiSettings().setMyLocationButtonEnabled(false);
    map.setMyLocationEnabled(true);
    }catch(Exception ex){ex.printStackTrace();}

    MapsInitializer.initialize(this);

}
@Override
public void onResume() {

    super.onResume();
    m.onResume();
}
@Override
public void onDestroy() {
    super.onDestroy();
    m.onDestroy();
}
@Override
public void onLowMemory() {

   super.onLowMemory();
   m.onLowMemory();
}
 @Override
public void onSaveInstanceState(Bundle outState){
    super.onSaveInstanceState(outState);
     m.onSaveInstanceState(outState);
  }
}

布局:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<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">


<com.google.android.gms.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

</RelativeLayout>

清单:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.voicesee"

android:versionCode="1"
android:versionName="1.0">

<uses-sdk
    android:minSdkVersion="9"
    android:targetSdkVersion="15" />

<permission
    android:name="com.example.voicesee.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.example.voicesee.permission.MAPS_RECEIVE" />
<!-- Copied from Google Maps Library/AndroidManifest.xml. -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"  />                                                  
<!-- The following two permissions are not required to use
 Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>


<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">
   <meta-data
   android:name="com.google.android.gms.version"
   android:value="@integer/google_play_services_version" />


    <activity
        android:name="com.example.voicesee.MainActivity"
        android:label="@string/app_name">
        <intent-filter>
           

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

     <meta-data
       android:name="com.google.android.maps.v2.API_KEY"
       android:value="AIzaSyAguDjIFiVWi18ll7Yh0oa8C7hWju1PUzI"/>


</application>

谢谢你的帮助!!


我遇到了类似的问题,我的问题是因为我选择了错误的调试密钥库。我正在使用 ubuntu 机器。由于我以 root 身份打开 eclipse,因此 eclipse 中的默认密钥库位于我的根文件夹(/root/.android/.android/debug.keystore)中,而我正在使用我的用户文件夹中的调试密钥库创建 api 密钥。我添加了一个指向已回答问题的链接:
Google Maps V2 在 android 2.2 上显示空白屏幕


您确定吗:您在 Google 控制台中的项目打开了

Google Maps Android API v2

  • 是的!!我确定,我做到了!


检查清单中的 api 密钥和应用程序的 SHA 密钥。您可以通过访问 console.developers.google.com 创建新的。

要查看 SHA 密钥Eclipse,请转到
--> windows>preferences>在左侧面板上选择android>点击build

查看 SHA 密钥 android studio
请参阅此链接 How to get the SHA-1 Fingerprint Certificate in Android Studio for debug mode?


在我的代码中,我用 supportMapfragment 更改了 mapview,我删除了我以前的 debug.keytool 并重建了它,然后我删除了我的旧 apikey 并创建了一个新密钥。看来我的问题是与 google play 服务的连接,因为它可以工作添加 GooglePlayServicesUtil.isGooglePlayServicesAvailable() 并在调用 setContentview()

之前验证与谷歌播放服务的连接后


您需要使用片段来封装您的地图,并且片段仅受 Android API 级别 11 及更高版本(3.0 及更高版本)支持。这可能是您的问题的原因。

正如这里提到的,您需要为您的 API 版本使用 SupportMapFragment。

这里是学习如何使用它的链接。

如果这不起作用,我猜是 API 密钥。之前我们遇到过加载网格和缩放按钮而不是地图的情况,关键是罪魁祸首。我会逐步完成此处的步骤,以确保您已正确完成所有操作(包括使用 google play 服务)


首先,我不明白您为什么在将地图放在 Acitivity 中时使用 MapView,因为这样做会更难显示地图,Google\\' s 文档状态:

For a simpler method of displaying a Map use MapFragment (or SupportMapFragment) if you are looking to target earlier platforms.

其次,如果你已经这样做了,那么你在实现它时犯了一些错误,因为你放置了:

1
MapsInitializer.initialize(this);

方法在错误的地方,如文档所述:

Use this class to initialize the Google Maps Android API if features need to be used before obtaining a map. It must be called because some classes such as BitmapDescriptorFactory and CameraUpdateFactory need to be initialized.

有关关于 android:MapView google maps api V2 看起来是空白的,只显示带有 /- 按钮的网格的更多相关文章

  1. 安卓apk修改(Android反编译apk) - 2

    最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路

  2. ruby-on-rails - 带有 Zeus 的 RSpec 3.1,我应该在 spec_helper 中要求 'rspec/rails' 吗? - 2

    使用rspec-rails3.0+,测试设置分为spec_helper和rails_helper我注意到生成的spec_helper不需要'rspec/rails'。这会导致zeus崩溃:spec_helper.rb:5:in`':undefinedmethod`configure'forRSpec:Module(NoMethodError)对thisissue最常见的回应是需要'rspec/rails'。但这是否会破坏仅使用spec_helper拆分rails规范和PORO规范的全部目的?或者这无关紧要,因为Zeus无论如何都会预加载Rails?我应该在我的spec_helper中做

  3. Ruby:如何使用带有散列的 'send' 方法调用方法? - 2

    假设我有一个类A,里面有一些方法。假设stringmethodName是这些方法之一,我已经知道我想给它什么参数。它们在散列中{'param1'=>value1,'param2'=>value2}所以我有:params={'param1'=>value1,'param2'=>value2}a=A.new()a.send(methodName,value1,value2)#callmethodnamewithbothparams我希望能够通过传递我的哈希以某种方式调用该方法。这可能吗? 最佳答案 确保methodName是一个符号,而

  4. ruby-on-rails - 带有 Pry 的 Rails 控制台 - 2

    当我进入Rails控制台时,我已将pry设置为加载代替irb。我找不到该页面或不记得如何将其恢复为默认行为,因为它似乎干扰了我的Rubymine调试器。有什么建议吗? 最佳答案 我刚发现问题,pry-railsgem。忘记了它的目的是让“railsconsole”打开pry。 关于ruby-on-rails-带有Pry的Rails控制台,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/question

  5. 带有 attr_accessor 的类上的 Ruby instance_eval - 2

    我了解instance_eval和class_eval之间的基本区别。我在玩弄时发现的是一些涉及attr_accessor的奇怪东西。这是一个例子:A=Class.newA.class_eval{attr_accessor:x}a=A.newa.x="x"a.x=>"x"#...expectedA.instance_eval{attr_accessor:y}A.y="y"=>NoMethodError:undefinedmethod`y='forA:Classa.y="y"=>"y"#WHATTT?这是怎么回事:instance_eval没有访问我们的A类(对象)然后它实际上将它添加到

  6. ruby-on-rails - 关于 Ruby 的一般问题 - 2

    我在我的rails应用程序中安装了来自github.com的acts_as_versioned插件,但有一段代码我不完全理解,我希望有人能帮我解决这个问题class_eval我知道block内的方法(或任何它是什么)被定义为类内的实例方法,但我在插件的任何地方都找不到定义为常量的CLASS_METHODS,而且我也不确定是什么here,并且有问题的代码从lib/acts_as_versioned.rb的第199行开始。如果有人愿意告诉我这里的内幕,我将不胜感激。谢谢-C 最佳答案 这是一个异端。http://en.wikipedia

  7. ruby-on-rails - Rails 渲染带有驼峰命名法的 json 对象 - 2

    我在一个简单的RailsAPI中有以下Controller代码:classApi::V1::AccountsControllerehead:not_foundendendend问题在于,生成的json具有以下格式:{id:2,name:'Simpleaccount',cash_flows:[{id:1,amount:34.3,description:'simpledescription'},{id:2,amount:1.12,description:'otherdescription'}]}我需要我生成的json是camelCase('cashFlows'而不是'cash_flows'

  8. ruby-on-rails - 在 Ruby 或 Rails 中,hash.merge({ :order => 'asc' }) can return a new hash with a new key. 什么可以返回带有已删除键的新散列? - 2

    在Ruby(或Rails)中,我们可以做到new_params=params.merge({:order=>'asc'})现在new_params是一个带有添加键:order的散列。但是是否有一行可以返回带有已删除key的散列?线路new_params=params.delete(:order)不会工作,因为delete方法返回值,仅此而已。我们必须分3步完成吗?tmp_params=paramstmp_params.delete(:order)returntmp_params有没有更好的方法?因为我想做一个new_params=(params[:order].blank?||para

  9. ruby - 我怎样才能更好地了解/了解更多关于 Ruby 的知识? - 2

    按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭9年前。我最近开始学习Ruby,这是我的第一门编程语言。我对语法感到满意,并且我已经完成了许多只教授相同基础知识的教程。我已经写了一些小程序(包括我自己的数组排序方法,在有人告诉我谷歌“冒泡排序”之前我认为它非常聪明),但我觉得我需要尝试更大更难的东西来理解更多关于Ruby.关于如何执行此操作的任何想法?

  10. ruby - 关于 Ruby 中 Dir[] 和 File.join() 的混淆 - 2

    我在Ruby中遇到了一个关于Dir[]和File.join()的简单程序,blobs_dir='/path/to/dir'Dir[File.join(blobs_dir,"**","*")].eachdo|file|FileUtils.rm_rf(file)ifFile.symlink?(file)我有两个困惑:首先,File.join(@blobs_dir,"**","*")中的第二个和第三个参数是什么意思?其次,Dir[]在Ruby中有什么用?我只知道它等价于Dir.glob(),但是,我对Dir.glob()确实不是很清楚。 最佳答案

随机推荐