├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── feature_request.md │ └── support_request.md ├── PULL_REQUEST_TEMPLATE │ └── pull_request_template.md ├── dependabot.yml ├── pull_request_template.md ├── snippet-bot.yml ├── stale.yml ├── sync-repo-settings.yaml └── workflows │ ├── build.yml │ └── dependabot.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── SECURITY.md ├── demo-java ├── app │ ├── .gitignore │ ├── build.gradle.kts │ ├── proguard-rules.pro │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── placesdemo │ │ │ ├── AutocompleteAddressActivity.java │ │ │ ├── CurrentPlaceActivity.java │ │ │ ├── FieldSelector.java │ │ │ ├── MainActivity.java │ │ │ ├── PlaceAutocompleteActivity.java │ │ │ ├── PlaceDetailsAndPhotosActivity.java │ │ │ ├── PlaceIsOpenActivity.java │ │ │ ├── PlacesDemoApplication.java │ │ │ ├── StringUtil.java │ │ │ ├── model │ │ │ ├── AddressType.java │ │ │ ├── AutocompleteEditText.java │ │ │ ├── Bounds.java │ │ │ ├── GeocodingResult.java │ │ │ ├── Geometry.java │ │ │ ├── LocationType.java │ │ │ └── PlusCode.java │ │ │ └── programmatic_autocomplete │ │ │ ├── LatLngAdapter.java │ │ │ ├── PlacePredictionAdapter.java │ │ │ └── ProgrammaticAutocompleteToolbarActivity.java │ │ └── res │ │ ├── drawable │ │ └── ic_search_black_24dp.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── activity_programmatic_autocomplete.xml │ │ ├── autocomplete_address_activity.xml │ │ ├── autocomplete_address_map.xml │ │ ├── current_place_activity.xml │ │ ├── place_autocomplete_activity.xml │ │ ├── place_details_and_photos_activity.xml │ │ ├── place_is_open_activity.xml │ │ └── place_prediction_item.xml │ │ ├── menu │ │ └── menu.xml │ │ ├── raw │ │ └── style_json.json │ │ └── values │ │ ├── dimens.xml │ │ └── strings.xml ├── build.gradle.kts ├── gradle.properties ├── gradle │ ├── libs.versions.toml │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── local.defaults.properties └── settings.gradle ├── demo-kotlin ├── app │ ├── .gitignore │ ├── build.gradle.kts │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── placesdemo │ │ │ ├── AutocompleteAddressActivity.kt │ │ │ ├── CurrentPlaceActivity.kt │ │ │ ├── FieldSelector.kt │ │ │ ├── MainActivity.kt │ │ │ ├── PlaceAutocompleteActivity.kt │ │ │ ├── PlaceDetailsAndPhotosActivity.kt │ │ │ ├── PlaceIsOpenActivity.kt │ │ │ ├── PlacesDemoApplication.kt │ │ │ ├── StringUtil.kt │ │ │ ├── model │ │ │ ├── AddressType.kt │ │ │ ├── AutocompleteEditText.kt │ │ │ ├── Bounds.kt │ │ │ ├── GeocodingResult.kt │ │ │ ├── Geometry.kt │ │ │ ├── LocationType.kt │ │ │ └── PlusCode.kt │ │ │ └── programmatic_autocomplete │ │ │ ├── LatLngAdapter.kt │ │ │ ├── PlacePredictionAdapter.kt │ │ │ └── ProgrammaticAutocompleteGeocodingActivity.kt │ │ └── res │ │ ├── drawable │ │ └── ic_search_black_24dp.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── activity_programmatic_autocomplete.xml │ │ ├── autocomplete_address_activity.xml │ │ ├── autocomplete_address_map.xml │ │ ├── current_place_activity.xml │ │ ├── place_autocomplete_activity.xml │ │ ├── place_details_and_photos_activity.xml │ │ ├── place_is_open_activity.xml │ │ └── place_prediction_item.xml │ │ ├── menu │ │ └── menu.xml │ │ ├── raw │ │ └── style_json.json │ │ └── values │ │ ├── dimens.xml │ │ └── strings.xml ├── build.gradle.kts ├── gradle.properties ├── gradle │ ├── libs.versions.toml │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── local.defaults.properties └── settings.gradle.kts ├── gradlew └── snippets ├── .gitignore ├── app ├── .gitignore ├── build.gradle.kts ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── google │ │ └── places │ │ ├── CurrentPlaceActivity.java │ │ ├── GetStartedActivity.java │ │ ├── PlaceAutocompleteActivity.java │ │ ├── PlaceDetailsActivity.java │ │ ├── PlaceIsOpenActivity.java │ │ ├── PlacePhotosActivity.java │ │ ├── PlacesIconActivity.java │ │ └── kotlin │ │ ├── CurrentPlaceActivity.kt │ │ ├── GetStartedActivity.kt │ │ ├── PlaceAutocompleteActivity.kt │ │ ├── PlaceDetailsActivity.kt │ │ ├── PlaceIsOpenActivity.kt │ │ ├── PlacePhotosActivity.kt │ │ └── PlacesIconActivity.kt │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ └── ic_launcher_background.xml │ ├── layout │ └── activity_main.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle.kts ├── gradle.properties ├── gradle ├── libs.versions.toml └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── local.defaults.properties └── settings.gradle /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners 16 | 17 | .github/ @googlemaps/admin 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: 'type: bug, triage me' 6 | assignees: '' 7 | 8 | --- 9 | 10 | Thanks for stopping by to let us know something could be better! 11 | 12 | --- 13 | **PLEASE READ** 14 | 15 | If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/). This will ensure a timely response. 16 | 17 | Discover additional support services for the Google Maps Platform, including developer communities, technical guidance, and expert support at the Google Maps Platform [support resources page](https://developers.google.com/maps/support/). 18 | 19 | If your bug or feature request is not related to this particular library, please visit the Google Maps Platform [issue trackers](https://developers.google.com/maps/support/#issue_tracker). 20 | 21 | Check for answers on StackOverflow with the [google-maps](http://stackoverflow.com/questions/tagged/google-maps) tag. 22 | 23 | --- 24 | 25 | Please be sure to include as much information as possible: 26 | 27 | #### Environment details 28 | 29 | 1. Specify the API at the beginning of the title (for example, "Places: ...") 30 | 2. OS type and version 31 | 3. Library version and other environment information 32 | 33 | #### Steps to reproduce 34 | 35 | 1. ? 36 | 37 | #### Code example 38 | 39 | ``` 40 | # example 41 | ``` 42 | 43 | #### Stack trace 44 | ``` 45 | # example 46 | ``` 47 | 48 | Following these steps will guarantee the quickest resolution possible. 49 | 50 | Thanks! 51 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this library 4 | title: '' 5 | labels: 'type: feature request, triage me' 6 | assignees: '' 7 | 8 | --- 9 | 10 | Thanks for stopping by to let us know something could be better! 11 | 12 | --- 13 | **PLEASE READ** 14 | 15 | If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/). This will ensure a timely response. 16 | 17 | Discover additional support services for the Google Maps Platform, including developer communities, technical guidance, and expert support at the Google Maps Platform [support resources page](https://developers.google.com/maps/support/). 18 | 19 | If your bug or feature request is not related to this particular library, please visit the Google Maps Platform [issue trackers](https://developers.google.com/maps/support/#issue_tracker). 20 | 21 | Check for answers on StackOverflow with the [google-maps](http://stackoverflow.com/questions/tagged/google-maps) tag. 22 | 23 | --- 24 | 25 | **Is your feature request related to a problem? Please describe.** 26 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 27 | 28 | **Describe the solution you'd like** 29 | A clear and concise description of what you want to happen. 30 | 31 | **Describe alternatives you've considered** 32 | A clear and concise description of any alternative solutions or features you've considered. 33 | 34 | **Additional context** 35 | Add any other context or screenshots about the feature request here. 36 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/support_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Support request 3 | about: If you have a support contract with Google, please create an issue in the Google 4 | Cloud Support console. 5 | title: '' 6 | labels: 'triage me, type: question' 7 | assignees: '' 8 | 9 | --- 10 | 11 | **PLEASE READ** 12 | 13 | If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/). This will ensure a timely response. 14 | 15 | Discover additional support services for the Google Maps Platform, including developer communities, technical guidance, and expert support at the Google Maps Platform [support resources page](https://developers.google.com/maps/support/). 16 | 17 | If your bug or feature request is not related to this particular library, please visit the Google Maps Platform [issue trackers](https://developers.google.com/maps/support/#issue_tracker). 18 | 19 | Check for answers on StackOverflow with the [google-maps](http://stackoverflow.com/questions/tagged/google-maps) tag. 20 | 21 | --- 22 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/pull_request_template.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Pull request 3 | about: Create a pull request 4 | label: 'triage me' 5 | --- 6 | Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: 7 | - [ ] Make sure to open a GitHub issue as a bug/feature request before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea 8 | - [ ] Ensure the tests and linter pass 9 | - [ ] Code coverage does not decrease (if any source code was changed) 10 | - [ ] Appropriate docs were updated (if necessary) 11 | 12 | Fixes # 🦕 13 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: gradle 4 | directory: "/./demo-java" 5 | schedule: 6 | interval: "weekly" 7 | open-pull-requests-limit: 10 8 | commit-message: 9 | prefix: chore(deps) 10 | - package-ecosystem: gradle 11 | directory: "/./demo-kotlin" 12 | schedule: 13 | interval: "weekly" 14 | open-pull-requests-limit: 10 15 | commit-message: 16 | prefix: chore(deps) 17 | - package-ecosystem: gradle 18 | directory: "/./snippets" 19 | schedule: 20 | interval: "weekly" 21 | open-pull-requests-limit: 10 22 | commit-message: 23 | prefix: chore(deps) 24 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | Thank you for opening a Pull Request! 2 | 3 | --- 4 | 5 | Before submitting your PR, there are a few things you can do to make sure it goes smoothly: 6 | - [ ] Make sure to open a GitHub issue as a bug/feature request before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea 7 | - [ ] Ensure the tests and linter pass 8 | - [ ] Code coverage does not decrease (if any source code was changed) 9 | - [ ] Appropriate docs were updated (if necessary) 10 | 11 | Fixes # 🦕 12 | -------------------------------------------------------------------------------- /.github/snippet-bot.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlemaps-samples/android-places-demos/7a99c941d5e19741cdfbe70fb3d539e1a4fcb797/.github/snippet-bot.yml -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Configuration for probot-stale - https://github.com/probot/stale 16 | 17 | # Number of days of inactivity before an Issue or Pull Request becomes stale 18 | daysUntilStale: 120 19 | 20 | # Number of days of inactivity before an Issue or Pull Request with the stale label is closed. 21 | # Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale. 22 | daysUntilClose: 180 23 | 24 | # Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled) 25 | onlyLabels: [] 26 | 27 | # Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable 28 | exemptLabels: 29 | - pinned 30 | - "type: bug" 31 | 32 | # Set to true to ignore issues in a project (defaults to false) 33 | exemptProjects: false 34 | 35 | # Set to true to ignore issues in a milestone (defaults to false) 36 | exemptMilestones: false 37 | 38 | # Set to true to ignore issues with an assignee (defaults to false) 39 | exemptAssignees: false 40 | 41 | # Label to use when marking as stale 42 | staleLabel: "stale" 43 | 44 | # Comment to post when marking as stale. Set to `false` to disable 45 | markComment: > 46 | This issue has been automatically marked as stale because it has not had 47 | recent activity. Please comment here if it is still valid so that we can 48 | reprioritize. Thank you! 49 | 50 | # Comment to post when removing the stale label. 51 | # unmarkComment: > 52 | # Your comment here. 53 | 54 | # Comment to post when closing a stale Issue or Pull Request. 55 | closeComment: > 56 | Closing this. Please reopen if you believe it should be addressed. Thank you for your contribution. 57 | 58 | # Limit the number of actions per hour, from 1-30. Default is 30 59 | limitPerRun: 10 60 | 61 | # Limit to only `issues` or `pulls` 62 | only: issues 63 | 64 | # Optionally, specify configuration settings that are specific to just 'issues' or 'pulls': 65 | # pulls: 66 | # daysUntilStale: 30 67 | # markComment: > 68 | # This pull request has been automatically marked as stale because it has not had 69 | # recent activity. It will be closed if no further activity occurs. Thank you 70 | # for your contributions. 71 | 72 | # issues: 73 | # exemptLabels: 74 | # - confirmed 75 | -------------------------------------------------------------------------------- /.github/sync-repo-settings.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # https://github.com/googleapis/repo-automation-bots/tree/main/packages/sync-repo-settings 16 | 17 | rebaseMergeAllowed: true 18 | squashMergeAllowed: true 19 | mergeCommitAllowed: false 20 | deleteBranchOnMerge: true 21 | branchProtectionRules: 22 | - pattern: main 23 | isAdminEnforced: false 24 | requiresStrictStatusChecks: false 25 | requiredStatusCheckContexts: 26 | - 'cla/google' 27 | - 'test' 28 | - 'snippet-bot check' 29 | - 'header-check' 30 | requiredApprovingReviewCount: 1 31 | requiresCodeOwnerReviews: true 32 | - pattern: master 33 | isAdminEnforced: false 34 | requiresStrictStatusChecks: false 35 | requiredStatusCheckContexts: 36 | - 'cla/google' 37 | - 'test' 38 | - 'snippet-bot check' 39 | - 'header-check' 40 | requiredApprovingReviewCount: 1 41 | requiresCodeOwnerReviews: true 42 | permissionRules: 43 | - team: admin 44 | permission: admin 45 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | name: Build demos 16 | 17 | # Controls when the action will run. Triggers the workflow on push or pull request 18 | # events but only for the master branch 19 | on: 20 | push: 21 | branches: [ main ] 22 | pull_request: 23 | branches: [ main ] 24 | repository_dispatch: 25 | types: [ build ] 26 | schedule: 27 | - cron: '0 0 * * 1' 28 | workflow_dispatch: 29 | 30 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 31 | jobs: 32 | build-demo-java: 33 | runs-on: ubuntu-22.04 34 | 35 | steps: 36 | - uses: actions/checkout@v4 37 | 38 | - name: set up JDK 17 39 | uses: actions/setup-java@v4.2.1 40 | with: 41 | java-version: '17' 42 | distribution: 'adopt' 43 | 44 | - name: Install NDK 45 | run: | 46 | sudo ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager --install "ndk;20.0.5594570" 47 | 48 | - name: Build and check 49 | run: cd demo-java && ./gradlew assembleDebug lint 50 | 51 | - name: Upload build reports 52 | if: always() 53 | uses: actions/upload-artifact@v4 54 | with: 55 | name: demo-java-build-reports 56 | path: demo-java/app/build/reports 57 | 58 | build-demo-kotlin: 59 | runs-on: ubuntu-22.04 60 | 61 | steps: 62 | - uses: actions/checkout@v4 63 | 64 | - name: set up JDK 17 65 | uses: actions/setup-java@v4.2.1 66 | with: 67 | java-version: '17' 68 | distribution: 'adopt' 69 | 70 | - name: Install NDK 71 | run: | 72 | sudo ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager --install "ndk;20.0.5594570" 73 | 74 | - name: Build and check 75 | run: cd demo-kotlin && ./gradlew assembleDebug lint 76 | 77 | - name: Upload build reports 78 | if: always() 79 | uses: actions/upload-artifact@v4 80 | with: 81 | name: demo-kotlin-build-reports 82 | path: demo-kotlin/app/build/reports 83 | 84 | build-snippets: 85 | runs-on: ubuntu-22.04 86 | 87 | steps: 88 | - uses: actions/checkout@v4 89 | 90 | - name: set up JDK 17 91 | uses: actions/setup-java@v4.2.1 92 | with: 93 | java-version: '17' 94 | distribution: 'adopt' 95 | 96 | - name: Install NDK 97 | run: | 98 | sudo ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager --install "ndk;20.0.5594570" 99 | 100 | - name: Build and check 101 | run: cd snippets && ./gradlew assembleDebug lint 102 | 103 | - name: Upload build reports 104 | if: always() 105 | uses: actions/upload-artifact@v4 106 | with: 107 | name: snippets-build-reports 108 | path: snippets/app/build/reports 109 | 110 | test: # used as required status check 111 | runs-on: ubuntu-22.04 112 | needs: 113 | - build-demo-java 114 | - build-demo-kotlin 115 | - build-snippets 116 | steps: 117 | - run: echo "Fail if all other steps are not successful" 118 | -------------------------------------------------------------------------------- /.github/workflows/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | name: Dependabot 16 | on: pull_request 17 | 18 | permissions: 19 | contents: write 20 | 21 | jobs: 22 | dependabot: 23 | runs-on: ubuntu-latest 24 | if: ${{ github.actor == 'dependabot[bot]' }} 25 | env: 26 | PR_URL: ${{github.event.pull_request.html_url}} 27 | GITHUB_TOKEN: ${{secrets.SYNCED_GITHUB_TOKEN_REPO}} 28 | steps: 29 | - name: approve 30 | run: gh pr review --approve "$PR_URL" 31 | - name: merge 32 | run: gh pr merge --auto --squash --delete-branch "$PR_URL" 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | .idea 3 | .gradle 4 | *.iml 5 | local.properties 6 | secrets.properties 7 | .DS_Store 8 | .java-version 9 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Google Open Source Community Guidelines 2 | 3 | At Google, we recognize and celebrate the creativity and collaboration of open 4 | source contributors and the diversity of skills, experiences, cultures, and 5 | opinions they bring to the projects and communities they participate in. 6 | 7 | Every one of Google's open source projects and communities are inclusive 8 | environments, based on treating all individuals respectfully, regardless of 9 | gender identity and expression, sexual orientation, disabilities, 10 | neurodiversity, physical appearance, body size, ethnicity, nationality, race, 11 | age, religion, or similar personal characteristic. 12 | 13 | We value diverse opinions, but we value respectful behavior more. 14 | 15 | Respectful behavior includes: 16 | 17 | * Being considerate, kind, constructive, and helpful. 18 | * Not engaging in demeaning, discriminatory, harassing, hateful, sexualized, or 19 | physically threatening behavior, speech, and imagery. 20 | * Not engaging in unwanted physical contact. 21 | 22 | Some Google open source projects [may adopt][] an explicit project code of 23 | conduct, which may have additional detailed expectations for participants. Most 24 | of those projects will use our [modified Contributor Covenant][]. 25 | 26 | [may adopt]: https://opensource.google/docs/releasing/preparing/#conduct 27 | [modified Contributor Covenant]: https://opensource.google/docs/releasing/template/CODE_OF_CONDUCT/ 28 | 29 | ## Resolve peacefully 30 | 31 | We do not believe that all conflict is necessarily bad; healthy debate and 32 | disagreement often yields positive results. However, it is never okay to be 33 | disrespectful. 34 | 35 | If you see someone behaving disrespectfully, you are encouraged to address the 36 | behavior directly with those involved. Many issues can be resolved quickly and 37 | easily, and this gives people more control over the outcome of their dispute. 38 | If you are unable to resolve the matter for any reason, or if the behavior is 39 | threatening or harassing, report it. We are dedicated to providing an 40 | environment where participants feel welcome and safe. 41 | 42 | ## Reporting problems 43 | 44 | Some Google open source projects may adopt a project-specific code of conduct. 45 | In those cases, a Google employee will be identified as the Project Steward, 46 | who will receive and handle reports of code of conduct violations. In the event 47 | that a project hasn’t identified a Project Steward, you can report problems by 48 | emailing opensource@google.com. 49 | 50 | We will investigate every complaint, but you may not receive a direct response. 51 | We will use our discretion in determining when and how to follow up on reported 52 | incidents, which may range from not taking action to permanent expulsion from 53 | the project and project-sponsored spaces. We will notify the accused of the 54 | report and provide them an opportunity to discuss it before any action is 55 | taken. The identity of the reporter will be omitted from the details of the 56 | report supplied to the accused. In potentially harmful situations, such as 57 | ongoing harassment or threats to anyone's safety, we may take action without 58 | notice. 59 | 60 | *This document was adapted from the [IndieWeb Code of Conduct][] and can also 61 | be found at .* 62 | 63 | [IndieWeb Code of Conduct]: https://indieweb.org/code-of-conduct 64 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to become a contributor and submit your own code 2 | 3 | ## Contributor License Agreements 4 | 5 | We'd love to accept your sample apps and patches! Before we can take them, we 6 | have to jump a couple of legal hurdles. 7 | 8 | Please fill out either the individual or corporate Contributor License Agreement 9 | (CLA). 10 | 11 | * If you are an individual writing original source code and you're sure you 12 | own the intellectual property, then you'll need to sign an [individual CLA] 13 | (http://code.google.com/legal/individual-cla-v1.0.html). 14 | * If you work for a company that wants to allow you to contribute your work, 15 | then you'll need to sign a [corporate CLA] 16 | (http://code.google.com/legal/corporate-cla-v1.0.html). 17 | 18 | Follow either of the two links above to access the appropriate CLA and 19 | instructions for how to sign and return it. Once we receive it, we'll be able to 20 | accept your pull requests. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Google Places SDK for Android Demos 2 | ==================================== 3 | ![GitHub contributors](https://img.shields.io/github/contributors/googlemaps/android-places-demos) 4 | ![Apache-2.0](https://img.shields.io/badge/license-Apache-blue) 5 | [![Discord](https://img.shields.io/discord/676948200904589322)](https://discord.gg/hYsWbmk) 6 | 7 | This repo contains the following apps that demonstrate use of the [Google Places SDK for Android](https://developers.google.com/places/android-sdk/): 8 | 9 | 1. [demo-kotlin](demo-kotlin) Kotlin demo app for the Places SDK. 10 | 2. [demo-java](demo-java) Java demo app for the Places SDK. 11 | 12 | Note that each folder contains a distinct sample and must be imported separately. Each project also contains two Gradle product flavors: 13 | 14 | 1. `gms`: Product flavor for samples using the Places SDK that uses Maps SDK for Android 15 | 2. `v3`: Product flavor for samples using the Places SDK that uses Maps SDK V3 BETA for Android 16 | 17 | Additionally, the [snippets](snippets) app contains code snippets used for documentation found in https://developers.google.com/places/android-sdk 18 | 19 | Getting Started 20 | --------------- 21 | 22 | These demos use the Gradle build system. 23 | 24 | First download the demos by cloning this repository or downloading an archived snapshot. (See the options on the right hand side.) 25 | 26 | In Android Studio, use the "Open an existing Android Studio project", and select one of the demo directories (`demo-kotlin` or `demo-java`). 27 | 28 | Alternatively use the `./gradlew build` command to build the project directly. 29 | 30 | The demos also require that you add your own API key: 31 | 1. [Get an API Key](https://developers.google.com/places/android-sdk/get-api-key). 32 | 2. Open the `local.properties` file in either demo project 33 | 3. Add a single line to `local.properties` that looks like `PLACES_API_KEY=YOUR_API_KEY`, where `YOUR_API_KEY` is the API key you obtained in the first step. You can also take a look at `local.defaults.properties` as an example. 34 | 4. Build and run. 35 | 36 | Support 37 | ------- 38 | 39 | - Stack Overflow: https://stackoverflow.com/questions/tagged/google-places-api 40 | 41 | If you've found an error in these samples, please file an issue: 42 | https://github.com/googlemaps/android-places-demos/issues 43 | 44 | Patches are encouraged, and may be submitted according to the instructions in 45 | CONTRIBUTING.md. 46 | 47 | License 48 | ------- 49 | 50 | Copyright 2019 Google, Inc. 51 | 52 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 53 | license agreements. See the NOTICE file distributed with this work for 54 | additional information regarding copyright ownership. The ASF licenses this 55 | file to you under the Apache License, Version 2.0 (the "License"); you may not 56 | use this file except in compliance with the License. You may obtain a copy of 57 | the License at 58 | 59 | http://www.apache.org/licenses/LICENSE-2.0 60 | 61 | Unless required by applicable law or agreed to in writing, software 62 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 63 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 64 | License for the specific language governing permissions and limitations under 65 | the License. 66 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Report a security issue 2 | 3 | To report a security issue, please use https://g.co/vulnz. We use 4 | https://g.co/vulnz for our intake, and do coordination and disclosure here on 5 | GitHub (including using GitHub Security Advisory). The Google Security Team will 6 | respond within 5 working days of your report on g.co/vulnz. 7 | 8 | To contact us about other bugs, please open an issue on GitHub. 9 | 10 | > **Note**: This file is synchronized from the https://github.com/googlemaps/.github repository. 11 | -------------------------------------------------------------------------------- /demo-java/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /demo-java/app/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | alias(libs.plugins.android.application) 3 | alias(libs.plugins.secrets.gradle.plugin) 4 | } 5 | 6 | android { 7 | namespace = "com.example.placesdemo" 8 | compileSdk = 35 9 | 10 | defaultConfig { 11 | applicationId = "com.example.placesdemo" 12 | minSdk = 23 13 | targetSdk = 35 14 | versionCode = 1 15 | versionName = "1.0" 16 | 17 | multiDexEnabled = true 18 | } 19 | 20 | java { 21 | toolchain { 22 | languageVersion.set(JavaLanguageVersion.of(21)) 23 | } 24 | } 25 | 26 | buildFeatures { 27 | viewBinding = true 28 | } 29 | } 30 | 31 | dependencies { 32 | implementation(libs.constraintlayout) 33 | implementation(libs.activity) 34 | implementation(libs.fragment) 35 | implementation(libs.navigation.fragment) 36 | implementation(libs.navigation.ui) 37 | 38 | implementation(libs.appcompat) 39 | implementation(libs.material) 40 | 41 | implementation(libs.volley) 42 | implementation(libs.glide) 43 | implementation(libs.viewbinding) 44 | implementation(libs.multidex) 45 | 46 | // Places and Maps SDKs 47 | implementation(libs.places) 48 | implementation(libs.play.services.maps) 49 | implementation(libs.android.maps.utils) 50 | } 51 | 52 | // Secrets for Google Maps API Keys 53 | secrets { 54 | // To add your Google Maps Platform API key to this project: 55 | // 1. Copy local.defaults.properties to secrets.properties 56 | // 2. In the secrets.properties file, replace PLACES_API_KEY=DEFAULT_API_KEY with a key from a 57 | // project with Places API enabled 58 | // 3. In the secrets.properties file, replace MAPS_API_KEY=DEFAULT_API_KEY with a key from a 59 | // project with Maps SDK for Android enabled (can be the same project and key as in Step 2) 60 | defaultPropertiesFileName = "local.defaults.properties" 61 | 62 | // Optionally specify a different file name containing your secrets. 63 | // The plugin defaults to "local.properties" 64 | propertiesFileName = "secrets.properties" 65 | } 66 | -------------------------------------------------------------------------------- /demo-java/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle.kts. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /demo-java/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 35 | 36 | 39 | 40 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 53 | 57 | 60 | 63 | 66 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /demo-java/app/src/main/java/com/example/placesdemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.placesdemo; 18 | 19 | import android.content.Intent; 20 | import android.os.Bundle; 21 | import android.widget.Toast; 22 | 23 | import androidx.annotation.Nullable; 24 | import androidx.appcompat.app.AppCompatActivity; 25 | 26 | import com.example.placesdemo.programmatic_autocomplete.ProgrammaticAutocompleteToolbarActivity; 27 | import com.google.android.libraries.places.api.Places; 28 | 29 | public class MainActivity extends AppCompatActivity { 30 | 31 | @Override 32 | protected void onCreate(@Nullable Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | setContentView(R.layout.activity_main); 35 | 36 | setLaunchActivityClickListener(R.id.autocomplete_button, PlaceAutocompleteActivity.class); 37 | setLaunchActivityClickListener(R.id.autocomplete_address_button, AutocompleteAddressActivity.class); 38 | setLaunchActivityClickListener(R.id.programmatic_autocomplete_button, ProgrammaticAutocompleteToolbarActivity.class 39 | ); 40 | setLaunchActivityClickListener(R.id.place_and_photo_button, PlaceDetailsAndPhotosActivity.class); 41 | setLaunchActivityClickListener(R.id.is_open_button, PlaceIsOpenActivity.class); 42 | setLaunchActivityClickListener(R.id.current_place_button, CurrentPlaceActivity.class); 43 | } 44 | 45 | private void setLaunchActivityClickListener( 46 | int onClickResId, Class activityClassToLaunch) { 47 | findViewById(onClickResId) 48 | .setOnClickListener( 49 | v -> { 50 | Intent intent = new Intent(MainActivity.this, activityClassToLaunch); 51 | startActivity(intent); 52 | }); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /demo-java/app/src/main/java/com/example/placesdemo/PlacesDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.placesdemo; 2 | 3 | import android.app.Application; 4 | import android.widget.Toast; 5 | 6 | import com.google.android.libraries.places.api.Places; 7 | 8 | public class PlacesDemoApplication extends Application { 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | 13 | final String apiKey = BuildConfig.PLACES_API_KEY; 14 | 15 | if (apiKey.equals("")) { 16 | Toast.makeText(this, getString(R.string.error_api_key), Toast.LENGTH_LONG).show(); 17 | return; 18 | } 19 | 20 | Places.initialize(getApplicationContext(), apiKey); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /demo-java/app/src/main/java/com/example/placesdemo/model/AutocompleteEditText.java: -------------------------------------------------------------------------------- 1 | package com.example.placesdemo.model; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.MotionEvent; 6 | 7 | public class AutocompleteEditText extends androidx.appcompat.widget.AppCompatEditText { 8 | public AutocompleteEditText(Context context) { 9 | super(context); 10 | } 11 | 12 | public AutocompleteEditText(Context context, AttributeSet attrs) { 13 | super(context, attrs); 14 | } 15 | 16 | @Override 17 | public boolean onTouchEvent(MotionEvent event) { 18 | super.onTouchEvent(event); 19 | 20 | switch (event.getAction()) { 21 | case MotionEvent.ACTION_DOWN: 22 | return true; 23 | 24 | case MotionEvent.ACTION_UP: 25 | performClick(); 26 | return true; 27 | } 28 | return false; 29 | } 30 | 31 | // Because we call this from onTouchEvent, this code will be executed for both 32 | // normal touch events and for when the system calls this using Accessibility 33 | @Override 34 | public boolean performClick() { 35 | super.performClick(); 36 | return true; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /demo-java/app/src/main/java/com/example/placesdemo/model/Bounds.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.example.placesdemo.model; 16 | 17 | import com.google.android.gms.maps.model.LatLng; 18 | import java.io.Serializable; 19 | 20 | /** The northeast and southwest points that delineate the outer bounds of a map. */ 21 | public class Bounds implements Serializable { 22 | 23 | private static final long serialVersionUID = 1L; 24 | /** The northeast corner of the bounding box. */ 25 | public LatLng northeast; 26 | /** The southwest corner of the bounding box. */ 27 | public LatLng southwest; 28 | 29 | @Override 30 | public String toString() { 31 | return String.format("[%s, %s]", northeast, southwest); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /demo-java/app/src/main/java/com/example/placesdemo/model/GeocodingResult.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.example.placesdemo.model; 16 | 17 | import androidx.annotation.NonNull; 18 | 19 | import java.io.Serializable; 20 | import java.util.Arrays; 21 | 22 | public class GeocodingResult implements Serializable { 23 | 24 | private static final long serialVersionUID = 1L; 25 | 26 | /** 27 | * The human-readable address of this location. 28 | * 29 | *

Often this address is equivalent to the "postal address," which sometimes differs from 30 | * country to country. (Note that some countries, such as the United Kingdom, do not allow 31 | * distribution of true postal addresses due to licensing restrictions.) This address is generally 32 | * composed of one or more address components. For example, the address "111 8th Avenue, New York, 33 | * NY" contains separate address components for "111" (the street number, "8th Avenue" (the 34 | * route), "New York" (the city) and "NY" (the US state). These address components contain 35 | * additional information. 36 | */ 37 | public String formattedAddress; 38 | 39 | /** 40 | * All the localities contained in a postal code. This is only present when the result is a postal 41 | * code that contains multiple localities. 42 | */ 43 | public String[] postcodeLocalities; 44 | 45 | /** Location information for this result. */ 46 | public Geometry geometry; 47 | 48 | /** 49 | * The types of the returned result. This array contains a set of zero or more tags identifying 50 | * the type of feature returned in the result. For example, a geocode of "Chicago" returns 51 | * "locality" which indicates that "Chicago" is a city, and also returns "political" which 52 | * indicates it is a political entity. 53 | */ 54 | public AddressType[] types; 55 | 56 | /** 57 | * Indicates that the geocoder did not return an exact match for the original request, though it 58 | * was able to match part of the requested address. You may wish to examine the original request 59 | * for misspellings and/or an incomplete address. 60 | * 61 | *

Partial matches most often occur for street addresses that do not exist within the locality 62 | * you pass in the request. Partial matches may also be returned when a request matches two or 63 | * more locations in the same locality. For example, "21 Henr St, Bristol, UK" will return a 64 | * partial match for both Henry Street and Henrietta Street. Note that if a request includes a 65 | * misspelled address component, the geocoding service may suggest an alternate address. 66 | * Suggestions triggered in this way will not be marked as a partial match. 67 | */ 68 | public boolean partialMatch; 69 | 70 | /** A unique identifier for this place. */ 71 | public String placeId; 72 | 73 | /** The Plus Code identifier for this place. */ 74 | public PlusCode plusCode; 75 | 76 | @NonNull 77 | @Override 78 | public String toString() { 79 | StringBuilder sb = new StringBuilder("[GeocodingResult"); 80 | if (partialMatch) { 81 | sb.append(" PARTIAL MATCH"); 82 | } 83 | sb.append(" placeId=").append(placeId); 84 | sb.append(" ").append(geometry); 85 | sb.append(", formattedAddress=").append(formattedAddress); 86 | sb.append(", types=").append(Arrays.toString(types)); 87 | if (postcodeLocalities != null && postcodeLocalities.length > 0) { 88 | sb.append(", postcodeLocalities=").append(Arrays.toString(postcodeLocalities)); 89 | } 90 | sb.append("]"); 91 | return sb.toString(); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /demo-java/app/src/main/java/com/example/placesdemo/model/Geometry.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.example.placesdemo.model; 16 | 17 | import androidx.annotation.NonNull; 18 | 19 | import com.google.android.gms.maps.model.LatLng; 20 | 21 | import java.io.Serializable; 22 | 23 | /** The geometry of a Geocoding result. */ 24 | public class Geometry implements Serializable { 25 | 26 | private static final long serialVersionUID = 1L; 27 | /** 28 | * The bounding box which can fully contain the returned result (optionally returned). Note that 29 | * these bounds may not match the recommended viewport. (For example, San Francisco includes the 30 | * Farallon islands, which are technically part of the city, but probably should not be returned 31 | * in the viewport.) 32 | */ 33 | public Bounds bounds; 34 | 35 | /** 36 | * The geocoded latitude/longitude value. For normal address lookups, this field is typically the 37 | * most important. 38 | */ 39 | public LatLng location; 40 | 41 | /** The level of certainty of this geocoding result. */ 42 | public LocationType locationType; 43 | 44 | /** 45 | * The recommended viewport for displaying the returned result. Generally the viewport is used to 46 | * frame a result when displaying it to a user. 47 | */ 48 | public Bounds viewport; 49 | 50 | @NonNull 51 | @Override 52 | public String toString() { 53 | return String.format( 54 | "[Geometry: %s (%s) bounds=%s, viewport=%s]", location, locationType, bounds, viewport); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /demo-java/app/src/main/java/com/example/placesdemo/model/LocationType.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.example.placesdemo.model; 16 | 17 | /** 18 | * Location types for a reverse geocoding request. Please see Reverse 20 | * Geocoding for more detail. 21 | */ 22 | public enum LocationType { 23 | /** 24 | * Restricts the results to addresses for which we have location information accurate down to 25 | * street address precision. 26 | */ 27 | ROOFTOP, 28 | 29 | /** 30 | * Restricts the results to those that reflect an approximation (usually on a road) interpolated 31 | * between two precise points (such as intersections). An interpolated range generally indicates 32 | * that rooftop geocodes are unavailable for a street address. 33 | */ 34 | RANGE_INTERPOLATED, 35 | 36 | /** 37 | * Restricts the results to geometric centers of a location such as a polyline (for example, a 38 | * street) or polygon (region). 39 | */ 40 | GEOMETRIC_CENTER, 41 | 42 | /** Restricts the results to those that are characterized as approximate. */ 43 | APPROXIMATE, 44 | 45 | /** 46 | * Indicates an unknown location type returned by the server. The Java Client for Google Maps 47 | * Services should be updated to support the new value. 48 | */ 49 | UNKNOWN; 50 | } 51 | -------------------------------------------------------------------------------- /demo-java/app/src/main/java/com/example/placesdemo/model/PlusCode.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.example.placesdemo.model; 16 | 17 | import java.io.Serializable; 18 | 19 | /** A Plus Code encoded location reference. */ 20 | public class PlusCode implements Serializable { 21 | 22 | private static final long serialVersionUID = 1L; 23 | 24 | /** The global Plus Code identifier. */ 25 | public String globalCode; 26 | 27 | /** The compound Plus Code identifier. May be null for locations in remote areas. */ 28 | public String compoundCode; 29 | 30 | @Override 31 | public String toString() { 32 | StringBuilder sb = new StringBuilder("[PlusCode: "); 33 | sb.append(globalCode); 34 | if (compoundCode != null) { 35 | sb.append(", compoundCode=").append(compoundCode); 36 | } 37 | sb.append("]"); 38 | return sb.toString(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /demo-java/app/src/main/java/com/example/placesdemo/programmatic_autocomplete/LatLngAdapter.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.example.placesdemo.programmatic_autocomplete; 16 | 17 | import com.google.android.gms.maps.model.LatLng; 18 | import com.google.gson.TypeAdapter; 19 | import com.google.gson.stream.JsonReader; 20 | import com.google.gson.stream.JsonToken; 21 | import com.google.gson.stream.JsonWriter; 22 | 23 | import java.io.IOException; 24 | 25 | /** Handle conversion from varying types of latitude and longitude representations. */ 26 | public class LatLngAdapter extends TypeAdapter { 27 | /** 28 | * Reads in a JSON object and try to create a LatLng in one of the following formats. 29 | * 30 | *

{
31 |      *   "lat" : -33.8353684,
32 |      *   "lng" : 140.8527069
33 |      * }
34 |      *
35 |      * {
36 |      *   "latitude": -33.865257570508334,
37 |      *   "longitude": 151.19287000481452
38 |      * }
39 | */ 40 | @Override 41 | public LatLng read(JsonReader reader) throws IOException { 42 | if (reader.peek() == JsonToken.NULL) { 43 | reader.nextNull(); 44 | return null; 45 | } 46 | 47 | double lat = 0; 48 | double lng = 0; 49 | boolean hasLat = false; 50 | boolean hasLng = false; 51 | 52 | reader.beginObject(); 53 | while (reader.hasNext()) { 54 | String name = reader.nextName(); 55 | if ("lat".equals(name) || "latitude".equals(name)) { 56 | lat = reader.nextDouble(); 57 | hasLat = true; 58 | } else if ("lng".equals(name) || "longitude".equals(name)) { 59 | lng = reader.nextDouble(); 60 | hasLng = true; 61 | } 62 | } 63 | reader.endObject(); 64 | 65 | if (hasLat && hasLng) { 66 | return new LatLng(lat, lng); 67 | } else { 68 | return null; 69 | } 70 | } 71 | 72 | /** Not supported. */ 73 | @Override 74 | public void write(JsonWriter out, LatLng value) throws IOException { 75 | throw new UnsupportedOperationException("Unimplemented method."); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /demo-java/app/src/main/java/com/example/placesdemo/programmatic_autocomplete/PlacePredictionAdapter.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package com.example.placesdemo.programmatic_autocomplete; 16 | 17 | import android.view.LayoutInflater; 18 | import android.view.View; 19 | import android.view.ViewGroup; 20 | import android.widget.TextView; 21 | import androidx.annotation.NonNull; 22 | import androidx.recyclerview.widget.RecyclerView; 23 | import com.example.placesdemo.R; 24 | import com.example.placesdemo.programmatic_autocomplete.PlacePredictionAdapter.PlacePredictionViewHolder; 25 | import com.google.android.libraries.places.api.model.AutocompletePrediction; 26 | import java.util.ArrayList; 27 | import java.util.List; 28 | 29 | /** 30 | * A {@link RecyclerView.Adapter} for a {@link com.google.android.libraries.places.api.model.AutocompletePrediction}. 31 | */ 32 | public class PlacePredictionAdapter extends RecyclerView.Adapter { 33 | 34 | private final List predictions = new ArrayList<>(); 35 | 36 | private OnPlaceClickListener onPlaceClickListener; 37 | 38 | @NonNull 39 | @Override 40 | public PlacePredictionViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { 41 | final LayoutInflater inflater = LayoutInflater.from(parent.getContext()); 42 | return new PlacePredictionViewHolder( 43 | inflater.inflate(R.layout.place_prediction_item, parent, false)); 44 | } 45 | 46 | @Override 47 | public void onBindViewHolder(@NonNull PlacePredictionViewHolder holder, int position) { 48 | final AutocompletePrediction prediction = predictions.get(position); 49 | holder.setPrediction(prediction); 50 | holder.itemView.setOnClickListener(v -> { 51 | if (onPlaceClickListener != null) { 52 | onPlaceClickListener.onPlaceClicked(prediction); 53 | } 54 | }); 55 | } 56 | 57 | @Override 58 | public int getItemCount() { 59 | return predictions.size(); 60 | } 61 | 62 | public void setPredictions(List predictions) { 63 | this.predictions.clear(); 64 | this.predictions.addAll(predictions); 65 | notifyDataSetChanged(); 66 | } 67 | 68 | public void setPlaceClickListener(OnPlaceClickListener onPlaceClickListener) { 69 | this.onPlaceClickListener = onPlaceClickListener; 70 | } 71 | 72 | public static class PlacePredictionViewHolder extends RecyclerView.ViewHolder { 73 | 74 | private final TextView title; 75 | private final TextView address; 76 | 77 | public PlacePredictionViewHolder(@NonNull View itemView) { 78 | super(itemView); 79 | title = itemView.findViewById(R.id.text_view_title); 80 | address = itemView.findViewById(R.id.text_view_address); 81 | } 82 | 83 | public void setPrediction(AutocompletePrediction prediction) { 84 | title.setText(prediction.getPrimaryText(null)); 85 | address.setText(prediction.getSecondaryText(null)); 86 | } 87 | } 88 | 89 | interface OnPlaceClickListener { 90 | void onPlaceClicked(AutocompletePrediction place); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /demo-java/app/src/main/res/drawable/ic_search_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 22 | 25 | 26 | -------------------------------------------------------------------------------- /demo-java/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 26 | 27 |