Open main menu

CDOT Wiki β

Changes

MAP524/DPS924 Lecture 9

2,459 bytes added, 00:08, 6 August 2015
Using Google Maps
* Go to your SDK Manager and make sure the latest versions of "Google Play services" and "Google Repository" are installed. When you do that - make sure to not install any other updates. The SDK Manager likes to suggest all kinds of updates that you don't need and will use up all your disk space.
* See [https://developers.google.com/android/guides/setup here]. Note it's talking about the build.gradle file inside the app subdirectory of your project.
* I didnYou'll need an emulator with the proprietary Google Play libraries installed. Your existing emulator might not have them.* For Google Maps you'll need a real device, the maps won't manage work on an Android emulator (with or without Google services on the image).** You can use the free [https://www.genymotion.com GenyMotion emulator] and follow unofficial [https://github.com/codepath/android_guides/wiki/Genymotion-2.0-Emulators-with-Google-Play-support setup instructions] to get this google maps to work in that emulator.*** To run GenyMotion on the [[ICT_USB_Sticks]] you'll need to install VirtualBox like so (as root): <code>apt-get install virtualbox-4.3</code> == Using Google Maps == === Obtain API Access === There are many guides [https://developers.google.com/maps/documentation/android/intro here]. You can use for low-volume purposes for free. Google will track your usage of the maps API using an API key - without a key you can't use the service in your app. * Use "keytool" command to make/view your key store.<source lang="bash">keytool -list -v -keystore /home/$USER/.android/debug.keystore</source>* You can use the output to get a key associated with your application (which you want to do in production). That doesn't seem to be required any version more for development purposes.* Obtain a Maps API key from the [https://code.google.com/apis/console Google APIs Console] (which is not the same as your [https://play.google.com/apps/publish/ Google Play developer console]) by providing your application's signing certificate and its package name. You'll obviously need a Google account.** Create a new project (you won't have a choice).** Enable the Google Maps Android API v2 under APIs.** In Credentials/Public API access add a new Android key.** I had to wait a minute for it to show up. === Code === * If you haven't already done it - follow the "Setup to use Google Play Services" section above.* [https://developers.google.com/maps/documentation/android/signup#add_the_api_key_to_your_application Add the API key] to your app.* The rest of the emulatorcode you can find in parts of [https://developers.google.com/maps/documentation/android/map this tutorial], but specifically to get the minimum going you'll need to:** Add the appropriate fragment XML code to your activity layout and position it so that it did work on my Nexus 5doesn't cover other elements in your activity.** Make your activity implement FragmentActivity.** Use getMapAsync() to set up your activity to be the callback for when the map loads.** Do something interesting in onMapReady()