代码之家  ›  专栏  ›  技术社区  ›  masiboo

如何添加谷歌地图使用最新的API在现有的老android项目?

  •  0
  • masiboo  · 技术社区  · 7 年前

    我有一个旧的Android项目,我使用了locationapi和googlemap。我发现很多API都更新了。如果我从androidstudio为Map activity生成一个新项目,它将生成文件并指示如何获取googleapi密钥以及如何在Google\u maps\u API.xml(debug)文件中添加该密钥。这是在app/debug/res/values/google\u maps\u api.xml生成的。此文件值在AndroidManifest.xml中读取为

        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />   
    

    我想对现有的旧Android项目做同样的事情。我生成googleapi密钥并将其添加到AndroidManifest.xml中

       <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="xxxxxxxxxx" />
    

    但它不起作用。我能看到一张空白地图。还在日志里呢shows:-

    https://developers.google.com/maps/documentation/android-api/start 对于 如何正确设置

    2 回复  |  直到 7 年前
        1
  •  0
  •   Faiz Mir    7 年前

    我测试了你的地图把我的Api密钥和它的工作。。

    请生成新的Api密钥并重试。

    按照以下步骤获取API密钥:

    Go to the Google Cloud Platform Console.
    1.Create or select a project.
    2.Click Continue to enable the API and any related services.
    3.On the Credentials page, get an API key. 
    Note: If you have an existing unrestricted API key, or a key with browser restrictions, you may use that key.

    这是我的地图截图

    Here is the Working Map

        2
  •  0
  •   Martin Zeitler    7 年前

    尝试获取新的 API key . 可能当前密钥已失效

    ... 由于包名称更改或签名密钥指纹更改。

    推荐文章