Skip to content

Commit 7768691

Browse files
authored
docs: Update README on how to provide GMP API Key. (googlemaps-samples#248)
* docs: Update README on how to provide GMP API Key. * fix references. * Update reference. * Update string. * Update references.
1 parent e37665b commit 7768691

File tree

28 files changed

+134
-104
lines changed

28 files changed

+134
-104
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ build/
44
*.iml
55
local.properties
66
.DS_Store
7+
secure.properties

ApiDemos/java/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ Alternatively use the `gradlew build` command to build the project directly.
3838
This demo app requires that you add your own Google Maps API key:
3939

4040
1. [Get a Maps API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key)
41-
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)
42-
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
41+
1. Create a file in the root directory called `secure.properties` (this file should *NOT* be under version control to protect your API key)
42+
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
4343
1. Build and run
4444

4545
Support

ApiDemos/java/app/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ android {
1515
versionName "1.0"
1616
multiDexEnabled true
1717

18-
// Read the API key from ApiDemos/java/secure.properties into R.string.maps_api_key
18+
// Read the API key from ./secure.properties into R.string.maps_api_key
1919
def secureProps = new Properties()
20-
if (file("../secure.properties").exists()) {
21-
file("../secure.properties")?.withInputStream { secureProps.load(it) }
20+
if (file("../../../secure.properties").exists()) {
21+
file("../../../secure.properties")?.withInputStream { secureProps.load(it) }
2222
}
2323
resValue "string", "maps_api_key", (secureProps.getProperty("MAPS_API_KEY") ?: "")
2424

2525
// To add your Maps API key to this project:
26-
// 1. Create a file ApiDemos/java/secure.properties
26+
// 1. Create a file ./secure.properties
2727
// 2. Add this line, where YOUR_API_KEY is your API key:
2828
// MAPS_API_KEY=YOUR_API_KEY
2929
}

ApiDemos/java/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1818
# org.gradle.parallel=true
1919
android.enableJetifier=true
20-
android.useAndroidX=true
20+
android.useAndroidX=true

ApiDemos/kotlin/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ Alternatively use the `gradlew build` command to build the project directly.
3434
This demo app requires that you add your own Google Maps API key:
3535

3636
1. [Get a Maps API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key)
37-
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)
38-
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
37+
1. Create a file in the root directory called `secure.properties` (this file should *NOT* be under version control to protect your API key)
38+
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
3939
1. Build and run
4040

4141
Support

ApiDemos/kotlin/app/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ android {
1515
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1616
multiDexEnabled true
1717

18-
// Read the API key from ApiDemos/kotlin/secure.properties into R.string.maps_api_key
18+
// Read the API key from ./secure.properties into R.string.maps_api_key
1919
def secureProps = new Properties()
20-
if (file("../secure.properties").exists()) {
21-
file("../secure.properties")?.withInputStream { secureProps.load(it) }
20+
if (file("../../../secure.properties").exists()) {
21+
file("../../../secure.properties")?.withInputStream { secureProps.load(it) }
2222
}
2323
resValue "string", "maps_api_key", (secureProps.getProperty("MAPS_API_KEY") ?: "")
2424

2525
// To add your Maps API key to this project:
26-
// 1. Create a file ApiDemos/kotlin/secure.properties
26+
// 1. Create a file ./secure.properties
2727
// 2. Add this line, where YOUR_API_KEY is your API key:
2828
// MAPS_API_KEY=YOUR_API_KEY
2929
}

ApiDemos/kotlin/app/src/main/res/values/google_maps_api.xml

Lines changed: 0 additions & 17 deletions
This file was deleted.

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ This repo contains the following samples:
1414
Displays a map on a Wear OS device. This sample demonstrates the basic
1515
setup required for a gradle-based Android Studio project.
1616
1. [Tutorials](https://github.com/googlemaps/android-samples/tree/master/tutorials): Samples
17-
associated with tutorials in the developer's guide. See each sample for a link to the associated
18-
guide.
17+
associated with tutorials in the developer's guide. See each sample for a link to the associated guide.
1918

2019

2120
Pre-requisites
@@ -37,12 +36,14 @@ In Android Studio, use the "Import non-Android Studio project" or
3736
repository.
3837
If prompted for a gradle configuration accept the default settings.
3938

40-
Alternatively use the "gradlew build" command to build the project directly.
39+
Alternatively use the `gradlew build` command to build the project directly.
4140

42-
Search for `YOUR_API_KEY` in the project and replace it with your API key.
43-
Some samples store this in the gradle.properties file and others store it in the google_maps_api.xml file.
44-
See the [Get Started with Google Maps Platform](https://developers.google.com/maps/gmp-get-started)
45-
guide to get an API key.
41+
The demo apps require that you add your own Google Maps API key:
42+
43+
1. [Get a Maps API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key)
44+
1. Create a file in the root directory called `secure.properties` (this file should *NOT* be under version control to protect your API key)
45+
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
46+
1. Build and run
4647

4748
Support
4849
-------

secure.properties.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This is a template for the `secure.properties` file
2+
# To use this, replace "YOUR_API_KEY" with your GMP API key and rename this file to `secure.properties`
3+
MAPS_API_KEY="YOUR_API_KEY"

tutorials/java/CurrentPlaceDetailsOnMap/README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ This sample uses the Gradle build system.
2222
"Import Project" option.
2323
1. Select the `CurrentPlaceDetailsOnMap` directory that you downloaded with this repository.
2424
1. If prompted for a gradle configuration, accept the default settings.
25-
Alternatively use the "gradlew build" command to build the project directly.
26-
1. Add your API key to your app's `gradle.properties` file.
27-
(For information on getting an API key, see the
28-
[documentation](https://developers.google.com/maps/documentation/android-api/signup).)
29-
25+
Alternatively use the `gradlew build` command to build the project directly.
26+
27+
This demo app requires that you add your own Google Maps API key:
28+
29+
1. [Get a Maps API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key)
30+
1. Create a file in the root directory called `secure.properties` (this file should *NOT* be under version control to protect your API key)
31+
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
32+
1. Build and run
33+
3034
Support
3135
-------
3236

tutorials/java/CurrentPlaceDetailsOnMap/app/build.gradle

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,19 @@ android {
1010
versionCode 1
1111
versionName "1.0"
1212
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13-
resValue "string", "google_maps_key", (project.findProperty("GOOGLE_MAPS_API_KEY") ?: "")
13+
14+
// Read the API key from ./secure.properties into R.string.maps_api_key
15+
def secureProps = new Properties()
16+
if (file("../../../../secure.properties").exists()) {
17+
file("../../../../secure.properties")?.withInputStream { secureProps.load(it) }
18+
}
19+
resValue "string", "maps_api_key", (secureProps.getProperty("MAPS_API_KEY") ?: "")
20+
21+
// To add your Maps API key to this project:
22+
// 1. Create a file ./secure.properties
23+
// 2. Add this line, where YOUR_API_KEY is your API key:
24+
// MAPS_API_KEY=YOUR_API_KEY
25+
1426
}
1527
buildTypes {
1628
debug {

tutorials/java/CurrentPlaceDetailsOnMap/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
-->
2020
<meta-data
2121
android:name="com.google.android.geo.API_KEY"
22-
android:value="@string/google_maps_key" />
22+
android:value="@string/maps_api_key" />
2323

2424
<activity
2525
android:name="com.example.currentplacedetailsonmap.MapsActivityCurrentPlace"

tutorials/java/CurrentPlaceDetailsOnMap/app/src/main/java/com/example/currentplacedetailsonmap/MapsActivityCurrentPlace.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected void onCreate(Bundle savedInstanceState) {
115115

116116
// [START_EXCLUDE silent]
117117
// Construct a PlacesClient
118-
Places.initialize(getApplicationContext(), getString(R.string.google_maps_key));
118+
Places.initialize(getApplicationContext(), getString(R.string.maps_api_key));
119119
placesClient = Places.createClient(this);
120120

121121
// Construct a FusedLocationProviderClient.

tutorials/java/MapWithMarker/README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@ This sample uses the Gradle build system.
2222
`tutorials/java/MapWithMarker` directory that you downloaded
2323
1. If prompted for a gradle configuration, accept the default settings.
2424
Alternatively use the `gradlew build` command to build the project directly.
25-
25+
2626
This demo app requires that you add your own Google Maps API key:
2727

28-
1. [Get a Maps API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key)
29-
1. Create a file in the `tutorials/java/MapWithMarker` directory called `secure.properties`
30-
(this file should *NOT* be under version control to protect your API key)
31-
1. Add a single line to `tutorials/java/MapWithMarker/secure.properties` that looks like
32-
`MAPS_API_KEY=YOUR_API_KEY`, where `YOUR_API_KEY` is the API key you obtained in the first step
33-
1. Build and run
28+
1. [Get a Maps API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key)
29+
1. Create a file in the root directory called `secure.properties` (this file should *NOT* be under version control to protect your API key)
30+
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
31+
1. Build and run
3432

3533
Support
3634
-------

tutorials/java/MapWithMarker/app/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ android {
1111
versionName "1.0"
1212
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1313

14-
// Read the API key from tutorials/java/MapWithMarker/app/secure.properties into R.string.maps_api_key
14+
// Read the API key from ./secure.properties into R.string.maps_api_key
1515
def secureProps = new Properties()
16-
if (file("secure.properties").exists()) {
17-
file("secure.properties")?.withInputStream { secureProps.load(it) }
16+
if (file("../../../../secure.properties").exists()) {
17+
file("../../../../secure.properties")?.withInputStream { secureProps.load(it) }
1818
}
1919
resValue "string", "maps_api_key", (secureProps.getProperty("MAPS_API_KEY") ?: "")
2020

2121
// To add your Maps API key to this project:
22-
// 1. Create a file tutorials/java/MapWithMarker/app/secure.properties
22+
// 1. Create a file ./secure.properties
2323
// 2. Add this line, where YOUR_API_KEY is your API key:
2424
// MAPS_API_KEY=YOUR_API_KEY
2525
}

tutorials/java/Polygons/README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@ This sample uses the Gradle build system.
2626

2727
This demo app requires that you add your own Google Maps API key:
2828

29-
1. [Get a Maps API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key)
30-
1. Create a file in the `tutorials/java/Polygons/app` directory called `secure.properties`
31-
(this file should *NOT* be under version control to protect your API key)
32-
1. Add a single line to `tutorials/java/Polygons/secure.properties` that looks like
33-
`MAPS_API_KEY=YOUR_API_KEY`, where `YOUR_API_KEY` is the API key you obtained in the first step
34-
1. Build and run
29+
1. [Get a Maps API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key)
30+
1. Create a file in the root directory called `secure.properties` (this file should *NOT* be under version control to protect your API key)
31+
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
32+
1. Build and run
3533

3634
Support
3735
-------

tutorials/java/Polygons/app/build.gradle

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ android {
1111
versionName "1.0"
1212
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1313

14-
// Read the API key from tutorials/java/Polygons/app/secure.properties into R.string.maps_api_key
14+
// Read the API key from ./secure.properties into R.string.maps_api_key
1515
def secureProps = new Properties()
16-
if (file("secure.properties").exists()) {
17-
file("secure.properties")?.withInputStream { secureProps.load(it) }
16+
if (file("../../../../secure.properties").exists()) {
17+
file("../../../../secure.properties")?.withInputStream { secureProps.load(it) }
1818
}
1919
resValue "string", "maps_api_key", (secureProps.getProperty("MAPS_API_KEY") ?: "")
2020

2121
// To add your Maps API key to this project:
22-
// 1. Create a file tutorials/java/Polygons/app/secure.properties
22+
// 1. Create a file ./secure.properties
2323
// 2. Add this line, where YOUR_API_KEY is your API key:
2424
// MAPS_API_KEY=YOUR_API_KEY
25+
2526
}
2627
buildTypes {
2728
release {
@@ -38,4 +39,4 @@ dependencies {
3839
testImplementation 'junit:junit:4.13'
3940
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
4041
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
41-
}
42+
}

tutorials/java/StyledMap/README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ This sample uses the Gradle build system.
2323
1. Select the `StyledMap` directory that you downloaded with this repository.
2424
1. If prompted for a gradle configuration, accept the default settings.
2525
Alternatively use the "gradlew build" command to build the project directly.
26-
1. Add your API key to your app's `gradle.properties` file.
27-
(For information on getting an API key, see the
28-
[documentation](https://developers.google.com/maps/documentation/android-api/signup).)
26+
27+
This demo app requires that you add your own Google Maps API key:
28+
29+
1. [Get a Maps API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key)
30+
1. Create a file in the root directory called `secure.properties` (this file should *NOT* be under version control to protect your API key)
31+
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
32+
1. Build and run
2933

3034
Support
3135
-------

tutorials/java/StyledMap/app/build.gradle

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,18 @@ android {
1010
versionCode 1
1111
versionName "1.0"
1212
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13-
resValue "string", "google_maps_key", (project.findProperty("GOOGLE_MAPS_API_KEY") ?: "")
13+
14+
// Read the API key from ./secure.properties into R.string.maps_api_key
15+
def secureProps = new Properties()
16+
if (file("../../../../secure.properties").exists()) {
17+
file("../../../../secure.properties")?.withInputStream { secureProps.load(it) }
18+
}
19+
resValue "string", "maps_api_key", (secureProps.getProperty("MAPS_API_KEY") ?: "")
20+
21+
// To add your Maps API key to this project:
22+
// 1. Create a file ./secure.properties
23+
// 2. Add this line, where YOUR_API_KEY is your API key:
24+
// MAPS_API_KEY=YOUR_API_KEY
1425
}
1526
buildTypes {
1627
release {

tutorials/java/StyledMap/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
-->
1919
<meta-data
2020
android:name="com.google.android.geo.API_KEY"
21-
android:value="@string/google_maps_key" />
21+
android:value="@string/maps_api_key" />
2222

2323
<activity android:name=".MapsActivityRaw"
2424
android:label="@string/title_activity_maps">
@@ -30,4 +30,4 @@
3030
</activity>
3131
</application>
3232

33-
</manifest>
33+
</manifest>

tutorials/kotlin/CurrentPlaceDetailsOnMap/README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@ This sample uses the Gradle build system.
2222
"Import Project" option.
2323
1. Select the `CurrentPlaceDetailsOnMap` directory that you downloaded with this repository.
2424
1. If prompted for a gradle configuration, accept the default settings.
25-
Alternatively use the "gradlew build" command to build the project directly.
26-
1. Add your API key to your app's `gradle.properties` file.
27-
(For information on getting an API key, see the
28-
[documentation](https://developers.google.com/maps/documentation/android-api/signup).)
25+
Alternatively use the `gradlew build` command to build the project directly.
26+
27+
This demo app requires that you add your own Google Maps API key:
28+
29+
1. [Get a Maps API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key)
30+
1. Create a file in the root directory called `secure.properties` (this file should *NOT* be under version control to protect your API key)
31+
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
32+
1. Build and run
33+
2934

3035
Support
3136
-------

tutorials/kotlin/CurrentPlaceDetailsOnMap/app/build.gradle

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,19 @@ android {
1212
versionCode 1
1313
versionName "1.0"
1414
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15-
resValue "string", "google_maps_key", (project.findProperty("GOOGLE_MAPS_API_KEY") ?: "")
15+
16+
// Read the API key from ./secure.properties into R.string.maps_api_key
17+
def secureProps = new Properties()
18+
if (file("../../../../secure.properties").exists()) {
19+
file("../../../../secure.properties")?.withInputStream { secureProps.load(it) }
20+
}
21+
resValue "string", "maps_api_key", (secureProps.getProperty("MAPS_API_KEY") ?: "")
22+
23+
// To add your Maps API key to this project:
24+
// 1. Create a file ./secure.properties
25+
// 2. Add this line, where YOUR_API_KEY is your API key:
26+
// MAPS_API_KEY=YOUR_API_KEY
27+
1628
}
1729
buildTypes {
1830
debug {

tutorials/kotlin/CurrentPlaceDetailsOnMap/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
-->
2020
<meta-data
2121
android:name="com.google.android.geo.API_KEY"
22-
android:value="@string/google_maps_key" />
22+
android:value="@string/maps_api_key" />
2323

2424
<activity
2525
android:name="com.example.currentplacedetailsonmap.MapsActivityCurrentPlace"
@@ -32,4 +32,4 @@
3232
</activity>
3333
</application>
3434

35-
</manifest>
35+
</manifest>

tutorials/kotlin/CurrentPlaceDetailsOnMap/app/src/main/java/com/example/currentplacedetailsonmap/MapsActivityCurrentPlace.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class MapsActivityCurrentPlace : AppCompatActivity(), OnMapReadyCallback {
8989

9090
// [START_EXCLUDE silent]
9191
// Construct a PlacesClient
92-
Places.initialize(applicationContext, getString(R.string.google_maps_key))
92+
Places.initialize(applicationContext, getString(R.string.maps_api_key))
9393
placesClient = Places.createClient(this)
9494

9595
// Construct a FusedLocationProviderClient.
@@ -407,4 +407,4 @@ class MapsActivityCurrentPlace : AppCompatActivity(), OnMapReadyCallback {
407407
// Used for selecting the current place.
408408
private const val M_MAX_ENTRIES = 5
409409
}
410-
}
410+
}

0 commit comments

Comments
 (0)