Friday, October 25, 2013

Developing Android # 2 Google Maps API - The Android Free

tumblr_inline_mu785g9kN11qfbwj9

Follow

previous articles in this section here

application

‘ll use Google maps and therefore the Google Maps API. By experience, I knew it was not as easy to configure everything to work, so this is the first step.

The steps that we will continue to make things work correctly are:

  • download and configure the Google Play Services
  • Get an API key
  • Define the specifications in the Application Manifest
  • Add a map to the application.

we go!


Download and configure the Google Play Services

This step is pretty simple. Once we have downloaded all the Android SDK, launch the SDK Manager to unburden one hand a version of the SDK or above Android 4.2.2 and on the other hand, the extra package Google Play Services.

image This is because now the API is distributed as part of the Google Play Services, and therefore, we need to install them. Once you have downloaded, we can find it in the folder / extras / google / google_play_services /. The next step is to import this folder as a library.

To do this, simply open Eclipse and click File -> Import -> Android -> Android Existing Code into Workspace and find the folder mentioned just above.

image Seller, we reference it to our project. To do so, click the right mouse button on your project -> Properties -> Android and paragraph add our library Library.

image In this way we have configured and installed the Google Play Services and we can move on to the next point.

To access servers with Google Maps Google Maps API we need to add a API key in our application. This key will be associated exclusively to our app through Android using certificates and work or not accordingly. So, we need above all SHA-1 fingerprint of our application to request the API key. But one thing.


Getting the SHA-1 fingerprint of our aplciación

It was a real quebradero

, but thanks to the help of kix2902 discovered that all the information is in the Eclipse -> Window -> Preferences -> Android -> Build

image

API

Once we and our footprint SHA-1, we move to the next step:

    • Open the Google APIs console
    • create a new project with the name you want
    • Let

    • paragraph below Services and activate Android Google Maps API v2

    image paragraph

  • Now let Access API -> Create New Android Key
  • We introduce the trace

  • SHA-1 followed by the package name. My
  • just generate API key and already have at our disposal
  • image

    API Key to our application

    Now that we have the API Key, we have to add it to our application to make it work.

    1. In the AndroidManifest.xml add the following as a child block (just before the end )

    where api_key is the API Key.

    2. We add the following permissions

    android.permission.INTERNET

    • Used by the API for downloading maps from servers.

      android.permission.ACCESS_NETWORK_STATE

    • allows the API to check the connection status to see if you can download data.
    • com.google.android.providers.gsf.permission.READ_GSERVICES API enables access to Google services web based.
    • android.permission.WRITE_EXTERNAL_STORAGE

    • API enables data stored in cache on the SD map.

    is also recommended to add the following if your application needs to access our position.

    • android.permission.ACCESS_COARSE_LOCATION API Allows use WiFi or mobile data (or both) to determine our location.

    • android.permission.ACCESS_FINE_LOCATION API Allows use GPS to determine our location accurately.

    In summary, we have to add the following:

    android:name=”android.permission.INTERNET”/>

    android:name=”android.permission.ACCESS_NETWORK_STATE”/>


    Android Google Maps API v2, but are recommended. ->
    Android:name=”android.permission.ACCESS_COARSE_LOCATION”/> android:name=”android.permission.ACCESS_FINE_LOCATION”/>

    Google Maps v2 uses OpenGL ES to render the maps. If you have not installed OpenGL ES v2, the map does not appear, and therefore is also recommended to add the following condition:

    With this we have configured our application.

    image spent and the last point: add a map. Once you have configured the Google Play Services, we have added the API Key and filled the AndroidManifest.xml, plays sting code.

    Add a map is very simple

    1. In the main.xml add the following snippet


    2. In this add MainActivity Side

    com.example.mapdemo package;

    android.app.Activity import, import
    android.os.Bundle;

    MainActivity public class extends Activity {

    @ Override protected void onCreate (Bundle savedInstanceState) {
    super.onCreate (savedInstanceState) setContentView
    (R.layout.main) ,

    }}

    3. And that's it, works flawlessly!

    image The next steps are going to be able to add points on the map and positions determined. Hopefully not too hard!

    Links

    • Google Maps API v2 [Google Dev]
    • Installing the Google Maps API [Google Dev]
    • Maps on Android [SGOliver]
    • Google API Console

    I remind you that the source code is on Github project

    Any questions, suggestions or questions you can find me on twitter!

  • No comments:

    Post a Comment