sábado, 16 de junho de 2012

Creating an Android App with Google Maps Integration (Part 2)

Regarding the part 1 of this tutorial: from this point i'm going to start using Android 2.3.3 on the emulator because the Android 4.0.3 gave me some problems.

Adding a mapView to your Android App

  • First we need to tell to our app where is library for the google maps. Go to the AndroidManifest.xml file and under <application> add this:
<uses-library android:name="com.google.android.maps" />

  • Now, because we want to get the maps from google we need to the app to access the internet. To do that we also need to add this line under the <manifest>:
<uses-permission android:name="android.permission.INTERNET" />

  • Go to the res/layout/main.xml file and replace all the xml with this one:
  • Now we need to get the Maps API key to insert on "Insert Maps API key here". To do that open the command line, go to the directory of the debug keystore (if you don't now yours go to eclipse preferences) and run this comand:
  • If it asks about a password just press enter.
  • You should see now a MD5 hash. Copy it and paste it in here to register your key: https://developers.google.com/android/maps-api-signup
  • Now you have your key to insert on the App. Do it.
  • Go to the main activity (mine is FoursquareMapActivity) and extend the class to MapActivity.
  • From here we just need to override some methods and add two lines of code to add zoom in and out buttons:
  • If you have errors in your code press "Ctrl + left shift + O" to add the imports that may be missing.
  • If you have your emulator running you can run your app and see the google maps working :).
  • To add a little more space we can take out the main title by going to the manifest and add this line 
    android:theme="@android:style/Theme.NoTitleBar"
    inside <activity>

Sem comentários:

Enviar um comentário