如何在一个应用程序中使用 google 远距离矩阵 api 键和 google 映射 api 键?

How to use a google distant matrix api key and an google maps api key in one app?

我正在为 android 编写一个应用程序,帮助我找到我家乡的最佳停车位 space。

为此,我在 android 中使用 Google 映射 API。我设法让它显示城市中的停车场。

现在我想使用 google 距离矩阵 API 来计算我的位置和不同停车场之间的车程时间,以及从停车场到用户特定位置的步行时间位置在镇上。

因为我必须使用

String url = "https://maps.googleapis.com/maps/api/distancematrix/json?"
       + "origins=" + start.latitude + "," + start.longitude
       + "&destinations="     +waypoints+"&sensor=false&mode=driving&key=GOOGLE_key";

我需要为 GOOGLE_key 添加一个 API 键。

我已经有一个用于远程矩阵的 API 键,但我在犹豫是否要在代码中使用它,因为在教程中他们建议不要这样做。

现在回答我的问题:

  1. 如何以及在哪里可以存储该密钥?
  2. 我想在代码中使用类似... + "&sensor=false&mode=driving&key=" + GOOGLE_key; 的东西而不使用 API 键。

附加信息:

在我的AndroidManifest.xml中是:

android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" 

并在 google_maps_api.xml 中:

<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</string>

感谢您的帮助。

创建一个变量,如 GOOGLE_key,然后通过 getResources().getSring()google_maps_key 字符串附加到此变量。现在,您可以使用 "&sensor=false&mode=driving&key=" + GOOGLE_key;