docs: Update README on how to provide GMP API Key. (#248)

* docs: Update README on how to provide GMP API Key.

* fix references.

* Update reference.

* Update string.

* Update references.
This commit is contained in:
Chris Arriola 2020-06-17 09:47:42 -07:00 committed by GitHub
parent e37665bebb
commit 7768691408
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 133 additions and 103 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ build/
*.iml
local.properties
.DS_Store
secure.properties

View File

@ -38,8 +38,8 @@ Alternatively use the `gradlew build` command to build the project directly.
This demo app requires that you add your own Google Maps API key:
1. [Get a Maps API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key)
1. Create a file in the `ApiDemos/java` directory called `secure.properties` (this file should *NOT* be under version control to protect your API key)
1. Add a single line to `ApiDemos/java/secure.properties` that looks like `MAPS_API_KEY=YOUR_API_KEY`, where `YOUR_API_KEY` is the API key you obtained in the first step
1. Create a file in the root directory called `secure.properties` (this file should *NOT* be under version control to protect your API key)
1. Add a single line to `secure.properties` that looks like `MAPS_API_KEY=YOUR_API_KEY`, where `YOUR_API_KEY` is the API key you obtained in the first step
1. Build and run
Support

View File

@ -15,15 +15,15 @@ android {
versionName "1.0"
multiDexEnabled true
// Read the API key from ApiDemos/java/secure.properties into R.string.maps_api_key
// Read the API key from ./secure.properties into R.string.maps_api_key
def secureProps = new Properties()
if (file("../secure.properties").exists()) {
file("../secure.properties")?.withInputStream { secureProps.load(it) }
if (file("../../../secure.properties").exists()) {
file("../../../secure.properties")?.withInputStream { secureProps.load(it) }
}
resValue "string", "maps_api_key", (secureProps.getProperty("MAPS_API_KEY") ?: "")
// To add your Maps API key to this project:
// 1. Create a file ApiDemos/java/secure.properties
// 1. Create a file ./secure.properties
// 2. Add this line, where YOUR_API_KEY is your API key:
// MAPS_API_KEY=YOUR_API_KEY
}

View File

@ -17,4 +17,4 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.enableJetifier=true
android.useAndroidX=true
android.useAndroidX=true

View File

@ -34,8 +34,8 @@ Alternatively use the `gradlew build` command to build the project directly.
This demo app requires that you add your own Google Maps API key:
1. [Get a Maps API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key)
1. Create a file in the `ApiDemos/kotlin/app` directory called `secure.properties` (this file should *NOT* be under version control to protect your API key)
1. Add a single line to `ApiDemos/kotlin/app/secure.properties` that looks like `MAPS_API_KEY=YOUR_API_KEY`, where `YOUR_API_KEY` is the API key you obtained in the first step
1. Create a file in the root directory called `secure.properties` (this file should *NOT* be under version control to protect your API key)
1. Add a single line to `secure.properties` that looks like `MAPS_API_KEY=YOUR_API_KEY`, where `YOUR_API_KEY` is the API key you obtained in the first step
1. Build and run
Support

View File

@ -15,15 +15,15 @@ android {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
// Read the API key from ApiDemos/kotlin/secure.properties into R.string.maps_api_key
// Read the API key from ./secure.properties into R.string.maps_api_key
def secureProps = new Properties()
if (file("../secure.properties").exists()) {
file("../secure.properties")?.withInputStream { secureProps.load(it) }
if (file("../../../secure.properties").exists()) {
file("../../../secure.properties")?.withInputStream { secureProps.load(it) }
}
resValue "string", "maps_api_key", (secureProps.getProperty("MAPS_API_KEY") ?: "")
// To add your Maps API key to this project:
// 1. Create a file ApiDemos/kotlin/secure.properties
// 1. Create a file ./secure.properties
// 2. Add this line, where YOUR_API_KEY is your API key:
// MAPS_API_KEY=YOUR_API_KEY
}

View File

@ -1,17 +0,0 @@
<resources>
<!--
TODO: Before you run your application, you need a Google Maps API key.
See this page for more information:
https://developers.google.com/maps/gmp-get-started
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.
Note: This resource is used for the debug build target. Update this file if you just want to run
the demo app.
-->
<string name="google_maps_key" translatable="false" templateMergeStrategy="preserve">
YOUR_API_KEY
</string>
</resources>

View File

@ -14,8 +14,7 @@ This repo contains the following samples:
Displays a map on a Wear OS device. This sample demonstrates the basic
setup required for a gradle-based Android Studio project.
1. [Tutorials](https://github.com/googlemaps/android-samples/tree/master/tutorials): Samples
associated with tutorials in the developer's guide. See each sample for a link to the associated
guide.
associated with tutorials in the developer's guide. See each sample for a link to the associated guide.
Pre-requisites
@ -37,12 +36,14 @@ In Android Studio, use the "Import non-Android Studio project" or
repository.
If prompted for a gradle configuration accept the default settings.
Alternatively use the "gradlew build" command to build the project directly.
Alternatively use the `gradlew build` command to build the project directly.
Search for `YOUR_API_KEY` in the project and replace it with your API key.
Some samples store this in the gradle.properties file and others store it in the google_maps_api.xml file.
See the [Get Started with Google Maps Platform](https://developers.google.com/maps/gmp-get-started)
guide to get an API key.
The demo apps require that you add your own Google Maps API key:
1. [Get a Maps API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key)
1. Create a file in the root directory called `secure.properties` (this file should *NOT* be under version control to protect your API key)
1. Add a single line to `secure.properties` that looks like `MAPS_API_KEY=YOUR_API_KEY`, where `YOUR_API_KEY` is the API key you obtained in the first step
1. Build and run
Support
-------

View File

@ -0,0 +1,3 @@
# This is a template for the `secure.properties` file
# To use this, replace "YOUR_API_KEY" with your GMP API key and rename this file to `secure.properties`
MAPS_API_KEY="YOUR_API_KEY"

View File

@ -22,11 +22,15 @@ This sample uses the Gradle build system.
"Import Project" option.
1. Select the `CurrentPlaceDetailsOnMap` directory that you downloaded with this repository.
1. If prompted for a gradle configuration, accept the default settings.
Alternatively use the "gradlew build" command to build the project directly.
1. Add your API key to your app's `gradle.properties` file.
(For information on getting an API key, see the
[documentation](https://developers.google.com/maps/documentation/android-api/signup).)
Alternatively use the `gradlew build` command to build the project directly.
This demo app requires that you add your own Google Maps API key:
1. [Get a Maps API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key)
1. Create a file in the root directory called `secure.properties` (this file should *NOT* be under version control to protect your API key)
1. Add a single line to `secure.properties` that looks like `MAPS_API_KEY=YOUR_API_KEY`, where `YOUR_API_KEY` is the API key you obtained in the first step
1. Build and run
Support
-------

View File

@ -10,7 +10,19 @@ android {
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
resValue "string", "google_maps_key", (project.findProperty("GOOGLE_MAPS_API_KEY") ?: "")
// Read the API key from ./secure.properties into R.string.maps_api_key
def secureProps = new Properties()
if (file("../../../../secure.properties").exists()) {
file("../../../../secure.properties")?.withInputStream { secureProps.load(it) }
}
resValue "string", "maps_api_key", (secureProps.getProperty("MAPS_API_KEY") ?: "")
// To add your Maps API key to this project:
// 1. Create a file ./secure.properties
// 2. Add this line, where YOUR_API_KEY is your API key:
// MAPS_API_KEY=YOUR_API_KEY
}
buildTypes {
debug {

View File

@ -19,7 +19,7 @@
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
android:value="@string/maps_api_key" />
<activity
android:name="com.example.currentplacedetailsonmap.MapsActivityCurrentPlace"

View File

@ -115,7 +115,7 @@ public class MapsActivityCurrentPlace extends AppCompatActivity
// [START_EXCLUDE silent]
// Construct a PlacesClient
Places.initialize(getApplicationContext(), getString(R.string.google_maps_key));
Places.initialize(getApplicationContext(), getString(R.string.maps_api_key));
placesClient = Places.createClient(this);
// Construct a FusedLocationProviderClient.

View File

@ -22,15 +22,13 @@ This sample uses the Gradle build system.
`tutorials/java/MapWithMarker` directory that you downloaded
1. If prompted for a gradle configuration, accept the default settings.
Alternatively use the `gradlew build` command to build the project directly.
This demo app requires that you add your own Google Maps API key:
1. [Get a Maps API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key)
1. Create a file in the `tutorials/java/MapWithMarker` directory called `secure.properties`
(this file should *NOT* be under version control to protect your API key)
1. Add a single line to `tutorials/java/MapWithMarker/secure.properties` that looks like
`MAPS_API_KEY=YOUR_API_KEY`, where `YOUR_API_KEY` is the API key you obtained in the first step
1. Build and run
1. [Get a Maps API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key)
1. Create a file in the root directory called `secure.properties` (this file should *NOT* be under version control to protect your API key)
1. Add a single line to `secure.properties` that looks like `MAPS_API_KEY=YOUR_API_KEY`, where `YOUR_API_KEY` is the API key you obtained in the first step
1. Build and run
Support
-------

View File

@ -11,15 +11,15 @@ android {
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// Read the API key from tutorials/java/MapWithMarker/app/secure.properties into R.string.maps_api_key
// Read the API key from ./secure.properties into R.string.maps_api_key
def secureProps = new Properties()
if (file("secure.properties").exists()) {
file("secure.properties")?.withInputStream { secureProps.load(it) }
if (file("../../../../secure.properties").exists()) {
file("../../../../secure.properties")?.withInputStream { secureProps.load(it) }
}
resValue "string", "maps_api_key", (secureProps.getProperty("MAPS_API_KEY") ?: "")
// To add your Maps API key to this project:
// 1. Create a file tutorials/java/MapWithMarker/app/secure.properties
// 1. Create a file ./secure.properties
// 2. Add this line, where YOUR_API_KEY is your API key:
// MAPS_API_KEY=YOUR_API_KEY
}

View File

@ -26,12 +26,10 @@ This sample uses the Gradle build system.
This demo app requires that you add your own Google Maps API key:
1. [Get a Maps API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key)
1. Create a file in the `tutorials/java/Polygons/app` directory called `secure.properties`
(this file should *NOT* be under version control to protect your API key)
1. Add a single line to `tutorials/java/Polygons/secure.properties` that looks like
`MAPS_API_KEY=YOUR_API_KEY`, where `YOUR_API_KEY` is the API key you obtained in the first step
1. Build and run
1. [Get a Maps API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key)
1. Create a file in the root directory called `secure.properties` (this file should *NOT* be under version control to protect your API key)
1. Add a single line to `secure.properties` that looks like `MAPS_API_KEY=YOUR_API_KEY`, where `YOUR_API_KEY` is the API key you obtained in the first step
1. Build and run
Support
-------

View File

@ -11,17 +11,18 @@ android {
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// Read the API key from tutorials/java/Polygons/app/secure.properties into R.string.maps_api_key
// Read the API key from ./secure.properties into R.string.maps_api_key
def secureProps = new Properties()
if (file("secure.properties").exists()) {
file("secure.properties")?.withInputStream { secureProps.load(it) }
if (file("../../../../secure.properties").exists()) {
file("../../../../secure.properties")?.withInputStream { secureProps.load(it) }
}
resValue "string", "maps_api_key", (secureProps.getProperty("MAPS_API_KEY") ?: "")
// To add your Maps API key to this project:
// 1. Create a file tutorials/java/Polygons/app/secure.properties
// 1. Create a file ./secure.properties
// 2. Add this line, where YOUR_API_KEY is your API key:
// MAPS_API_KEY=YOUR_API_KEY
}
buildTypes {
release {
@ -38,4 +39,4 @@ dependencies {
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
}

View File

@ -23,9 +23,13 @@ This sample uses the Gradle build system.
1. Select the `StyledMap` directory that you downloaded with this repository.
1. If prompted for a gradle configuration, accept the default settings.
Alternatively use the "gradlew build" command to build the project directly.
1. Add your API key to your app's `gradle.properties` file.
(For information on getting an API key, see the
[documentation](https://developers.google.com/maps/documentation/android-api/signup).)
This demo app requires that you add your own Google Maps API key:
1. [Get a Maps API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key)
1. Create a file in the root directory called `secure.properties` (this file should *NOT* be under version control to protect your API key)
1. Add a single line to `secure.properties` that looks like `MAPS_API_KEY=YOUR_API_KEY`, where `YOUR_API_KEY` is the API key you obtained in the first step
1. Build and run
Support
-------

View File

@ -10,7 +10,18 @@ android {
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
resValue "string", "google_maps_key", (project.findProperty("GOOGLE_MAPS_API_KEY") ?: "")
// Read the API key from ./secure.properties into R.string.maps_api_key
def secureProps = new Properties()
if (file("../../../../secure.properties").exists()) {
file("../../../../secure.properties")?.withInputStream { secureProps.load(it) }
}
resValue "string", "maps_api_key", (secureProps.getProperty("MAPS_API_KEY") ?: "")
// To add your Maps API key to this project:
// 1. Create a file ./secure.properties
// 2. Add this line, where YOUR_API_KEY is your API key:
// MAPS_API_KEY=YOUR_API_KEY
}
buildTypes {
release {

View File

@ -18,7 +18,7 @@
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
android:value="@string/maps_api_key" />
<activity android:name=".MapsActivityRaw"
android:label="@string/title_activity_maps">
@ -30,4 +30,4 @@
</activity>
</application>
</manifest>
</manifest>

View File

@ -22,10 +22,15 @@ This sample uses the Gradle build system.
"Import Project" option.
1. Select the `CurrentPlaceDetailsOnMap` directory that you downloaded with this repository.
1. If prompted for a gradle configuration, accept the default settings.
Alternatively use the "gradlew build" command to build the project directly.
1. Add your API key to your app's `gradle.properties` file.
(For information on getting an API key, see the
[documentation](https://developers.google.com/maps/documentation/android-api/signup).)
Alternatively use the `gradlew build` command to build the project directly.
This demo app requires that you add your own Google Maps API key:
1. [Get a Maps API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key)
1. Create a file in the root directory called `secure.properties` (this file should *NOT* be under version control to protect your API key)
1. Add a single line to `secure.properties` that looks like `MAPS_API_KEY=YOUR_API_KEY`, where `YOUR_API_KEY` is the API key you obtained in the first step
1. Build and run
Support
-------

View File

@ -12,7 +12,19 @@ android {
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
resValue "string", "google_maps_key", (project.findProperty("GOOGLE_MAPS_API_KEY") ?: "")
// Read the API key from ./secure.properties into R.string.maps_api_key
def secureProps = new Properties()
if (file("../../../../secure.properties").exists()) {
file("../../../../secure.properties")?.withInputStream { secureProps.load(it) }
}
resValue "string", "maps_api_key", (secureProps.getProperty("MAPS_API_KEY") ?: "")
// To add your Maps API key to this project:
// 1. Create a file ./secure.properties
// 2. Add this line, where YOUR_API_KEY is your API key:
// MAPS_API_KEY=YOUR_API_KEY
}
buildTypes {
debug {

View File

@ -19,7 +19,7 @@
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
android:value="@string/maps_api_key" />
<activity
android:name="com.example.currentplacedetailsonmap.MapsActivityCurrentPlace"
@ -32,4 +32,4 @@
</activity>
</application>
</manifest>
</manifest>

View File

@ -89,7 +89,7 @@ class MapsActivityCurrentPlace : AppCompatActivity(), OnMapReadyCallback {
// [START_EXCLUDE silent]
// Construct a PlacesClient
Places.initialize(applicationContext, getString(R.string.google_maps_key))
Places.initialize(applicationContext, getString(R.string.maps_api_key))
placesClient = Places.createClient(this)
// Construct a FusedLocationProviderClient.
@ -407,4 +407,4 @@ class MapsActivityCurrentPlace : AppCompatActivity(), OnMapReadyCallback {
// Used for selecting the current place.
private const val M_MAX_ENTRIES = 5
}
}
}

View File

@ -22,15 +22,14 @@ This sample uses the Gradle build system.
`tutorials/kotlin/MapWithMarker` directory that you downloaded
1. If prompted for a gradle configuration, accept the default settings.
Alternatively use the `gradlew build` command to build the project directly.
This demo app requires that you add your own Google Maps API key:
1. [Get a Maps API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key)
1. Create a file in the `tutorials/kotlin/MapWithMarker` directory called `secure.properties`
(this file should *NOT* be under version control to protect your API key)
1. Add a single line to `tutorials/kotlin/MapWithMarker/secure.properties` that looks like
`MAPS_API_KEY=YOUR_API_KEY`, where `YOUR_API_KEY` is the API key you obtained in the first step
1. Build and run
1. [Get a Maps API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key)
1. Create a file in the root directory called `secure.properties` (this file should *NOT* be under version control to protect your API key)
1. Add a single line to `secure.properties` that looks like `MAPS_API_KEY=YOUR_API_KEY`, where `YOUR_API_KEY` is the API key you obtained in the first step
1. Build and run
Support
-------

View File

@ -13,15 +13,15 @@ android {
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// Read the API key from tutorials/kotlin/MapWithMarker/app/secure.properties into R.string.maps_api_key
// Read the API key from ./secure.properties into R.string.maps_api_key
def secureProps = new Properties()
if (file("secure.properties").exists()) {
file("secure.properties")?.withInputStream { secureProps.load(it) }
if (file("../../../../secure.properties").exists()) {
file("../../../../secure.properties")?.withInputStream { secureProps.load(it) }
}
resValue "string", "maps_api_key", (secureProps.getProperty("MAPS_API_KEY") ?: "")
// To add your Maps API key to this project:
// 1. Create a file tutorials/kotlin/MapWithMarker/app/secure.properties
// 1. Create a file ./secure.properties
// 2. Add this line, where YOUR_API_KEY is your API key:
// MAPS_API_KEY=YOUR_API_KEY
}

View File

@ -23,15 +23,13 @@ This sample uses the Gradle build system.
1. Select the `Polygons` directory that you downloaded with this repository.
1. If prompted for a gradle configuration, accept the default settings.
Alternatively use the `gradlew build` command to build the project directly.
This demo app requires that you add your own Google Maps API key:
1. [Get a Maps API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key)
1. Create a file in the `tutorials/kotlin/Polygons/app` directory called `secure.properties`
(this file should *NOT* be under version control to protect your API key)
1. Add a single line to `tutorials/kotlin/Polygons/secure.properties` that looks like
`MAPS_API_KEY=YOUR_API_KEY`, where `YOUR_API_KEY` is the API key you obtained in the first step
1. Build and run
1. [Get a Maps API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key)
1. Create a file in the root directory called `secure.properties` (this file should *NOT* be under version control to protect your API key)
1. Add a single line to `secure.properties` that looks like `MAPS_API_KEY=YOUR_API_KEY`, where `YOUR_API_KEY` is the API key you obtained in the first step
1. Build and run
Support
-------

View File

@ -13,15 +13,15 @@ android {
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// Read the API key from tutorials/java/Polygons/app/secure.properties into R.string.maps_api_key
// Read the API key from ./secure.properties into R.string.maps_api_key
def secureProps = new Properties()
if (file("secure.properties").exists()) {
file("secure.properties")?.withInputStream { secureProps.load(it) }
if (file("../../../../secure.properties").exists()) {
file("../../../../secure.properties")?.withInputStream { secureProps.load(it) }
}
resValue "string", "maps_api_key", (secureProps.getProperty("MAPS_API_KEY") ?: "")
// To add your Maps API key to this project:
// 1. Create a file tutorials/java/Polygons/app/secure.properties
// 1. Create a file ./secure.properties
// 2. Add this line, where YOUR_API_KEY is your API key:
// MAPS_API_KEY=YOUR_API_KEY
}