We taste the API v2 maps for Android from Google

And on our street, trucks with ice cream cookies and marmalades turn over ! As already mentioned , a new version of the API has been released. And even briefly it was told what is new there. So far, I can’t reveal all the improvements, from the point of view of the developer. But I’m ready to highlight some of the special advantages of developing applications using cards.

The first, and most probably delicious - now you can use fragments in full, instead of MapView. To do this, just insert the following code into the markup:


Secondly, it has become much more convenient to work with pins. True, now you need to get used to the fact that they are called markers, and it will be much more convenient. Now you do not need to fence ItemizedOverlay, and the like. Now it’s quite simple to execute the addMarker (MarkerOptions options) method with the necessary parameters, and the marker will flaunt at the specified position.

The third plus - it has become very convenient to draw objects on the map that can be zoomed and scrolled along with the map without any problems! Just add a shape ( addPolygon method (PolygonOptions options) ) or a line ( addPolyline method (PolylineOptions options) ) to the map, that's all. This means that now you can easily paint over the country, city, district ... Your car?) Yes, anything!



The following cons caught my eye:

  1. Now, to work with maps, the user must have installed the "Maps" application from Google itself. Otherwise, the error that "Google Maps application is missing" spits out in the log. But the application does not tell the user about this, which can piss him off. You can probably make a crutch, but it is a pity that he is not there right away. PS: I have CyanogenMod on the device, and I caught the error.
  2. It’s also impossible to do without the application “Google Play Services”. True, the user will be informed about this problem .., but not in a very beautiful form. I have not yet looked for ways to make this post more attractive.
  3. It seems that moving to a new version of the API will be unnecessarily laborious, which is a little depressing. Especially if a lot has already been done, but still a lot of work remains to be done, and the new chips are just what you need.
  4. Of course, for someone it may be critical that is only compatible with Android 2.2+


Not scared away? Then proceed to launch our first example.

First, we need to install / update the Google Play services SDK. To do this, do the following:
  • Launch Android SDK Manager
  • Select “Extras” → “Google Play services” to install
  • Click the “Install packages” button


After the installation is completed, at / extras / google / google_play_services you can find the libproject / google-play-services_lib and samples / maps folders. From the contents of the first folder you need to make a module, which we will then connect to the project. And from the second - just an example of an application for working with cards. I advise you first to copy these folders to the directory where you have the projects, and already work there on them, so that the SDK always contains a clean copy of the library with examples.

Unfortunately, I can’t suggest how to check all this in Eclipse. And here is a cheat sheet on how to do this in Intellij Idea.
Deploying an example project in Intellij Idea
  • File → New Project ...
  • Create project from existing sources → Next
  • Set the full path to samples / maps in Project files location and click Next, Next ...
  • File -> Project Structure -> Modules -> Module SDK: Android 4.2 Google APIs -> OK
  • In google-play-services_lib / src, create a file com / google / Hack.java with approximately the following contents:
    package com.google;
    public class Hack {
    	// Empty class to ensure there is a src folder.
    }
    

    It is necessary for Idea to create a module from this directory normally.
  • In the folder google-play-services_lib / libs copy android-support-v4.jar. It will be required for compatibility with older versions of Android
  • File → Project Structure → Modules → “Plus” above the second column → Module
  • Create module from existing sources → Specify the path to google-play-services_lib → Next, Next ...
  • On the right, click “Plus” → Jars or directories → google-play-services_lib / libs → Ok
  • Put a check mark next to the line in the list
  • In the second column, select another module (accordingly, the project) → “Plus” on the right → Module Dependency ... → OK → OK


Startup problems did occur, but were pretty minor.

To earn cards it remains to get a new API_KEY - the old one does not fit now. I will allow myself to describe in more detail this process, which in brief is uv. djvu explained here :

  1. Create SHA1 fingerprint from your debit or release key
  2. Go to the console
  3. Create project ... → Enter the name of the project, for example, “Google Maps Android API v2 test project”
  4. Switch Google Maps Android API v2 translate from “off” to “on”
  5. We agree with the “terms” (otherwise we say goodbye to the Google Maps Android API v2).
  6. In the left navbar, go to the Access API menu and press the “Create new Android key ...” button located at the bottom.
  7. Enter “; <package name> ”. In my case, the package name was com.example.mapdemo. If you are not sure about the name of your package, you can easily spy it in the AndroidManiffest.xml file created when creating the application, in the first manifest tag, the value of the package attribute.
  8. Click the Create button.
  9. The resulting key is inserted into AndroidManifest.xml

  10. Let's get started!


The resulting application will have a lot of interesting things, I advise you to study as thoroughly as possible.

PS: all the main documentation for the new API is collected here .

Easy and successful geocoding to you!

Also popular now: