And on our street trucks with
cookies are being turned over ice cream and marmalades! As already
mentioned , a new version of the API has been released. And even in brief it was told what was new there. I, while, cannot uncover all improvements, from the point of view of the developer. But some special advantages of developing applications using maps are ready to be highlighted.
The first, and probably the most delicious, is now possible to use fragments at all, instead of MapView. To do this, simply insert the following code into the markup:
<fragment android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.SupportMapFragment"/>
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 is enough just to execute the
addMarker (MarkerOptions options) method with the necessary parameters, and the marker will show off at the specified position.
')
The third plus is that it has become absolutely convenient to draw objects on the map that will easily zoom in and scroll along with the map, without any problems! Simply add a shape (the
addPolygon method
(PolygonOptions options) ) or a line (the
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, whatever!
The following minuses rushed into my eyes:
- Now, to work with maps, the user must have the Maps application from Google itself installed. Otherwise, an error is spilled into the log that "Google Maps application is missing". But the application does not tell the user about it, which can annoy him. Probably, you can make a crutch, but it is a pity that it is not immediately. PS: I have CyanogenMod on the device, and I caught the error.
- It is also impossible to do without the application “Google Play Services”. True, this problem will be reported to the user .., but not in a very beautiful form. I have not yet looked for ways to make this message more appealing.
- It seems that the move to the new version of the API will be unnecessarily laborious, which is a little depressing. Especially if a lot has already been done, but not a little work remains to be done, and new chips are just what you need.
- Of course, it may be critical for someone that is compatible only with Android 2.2+
Do not scare? 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 to install the item “Extras” → “Google Play services”
- Click the “Install packages” button
After the installation is complete, you can find the libproject / google-play-services_lib and samples / maps folders at <android-sdk> / extras / google / google_play_services. 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 maps. I advise you to first copy these folders to the directory where your projects are located, and already work on them there, so that the SDK always contains a clean copy of the library with examples.
Unfortunately, I cannot tell how to check all this in Eclipse. But cheat sheet how to do it in Intellij Idea bring.
Deploying the sample project in Intellij IdeaStartup problems have happened, but they were pretty minor.
To earn the cards, it remains to receive a new API_KEY - the old one is no longer suitable. I will allow myself to describe this process in more detail, which in brief is uv.
djvu explained
here :
- Create SHA1 fingerprint from your debazh or release key
- We go to the console
- Create project ... → Enter the name of the project, for example “Google Maps Android API v2 test project”
- Switch Google Maps Android API v2 translate from “off” to “on”
- We agree with “terms” (otherwise, we say goodbye to Google Maps Android API v2).
- In the left navbar, go to the API Access menu and click the “Create new Android key ...” button located below.
- Enter “<SHA1>; <package name>”. In my case, the package name was com.example.mapdemo. If you are not sure of the name of your package, you can easily look at it in the AndroidManiffest.xml file created during application creation, in the first manifest tag, the value of the package attribute.
- We press the button Create.
- The resulting key is inserted into AndroidManifest.xml
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="your_api_key"/>
- Run!
In the resulting application will be a lot of interesting things, I advise you to study as thoroughly as possible.
PS: all the main documentation on the new API is collected
here .
Easy and successful geocoding you!