(Android basics): The simplest android Google map application

Source: Internet
Author: User

How simple is it? Look, it just shows the map:

If you want to write an android Google map application, it is more difficult to prepare it than to write other applications. Because:

  1. The android Google map API is not open-source and free. It is Google's private software, although it is free;
  2. This API is always dependent on downloading map information from Google.
The first article is easy to handle. I am using android 2.1. Other versions, such as 1.5, need to be similar. Google map api needs to be imported into the project, which is not available by default. By default, a version of android, such as android 2.1, needs to be changed to the corresponding version of google apis. The version must be consistent with that of android. This google apis is an android superset of the same version, including google's private app api. For example:

In this way, you can use the following in the project:
Com. google. android. maps. MapActivity
This is not enough. google needs a signature fingerprint mechanism. It must first register with google and include this fingerprint in the application before downloading the map information. That is to say, the fingerprint information should be carried in each download of the MAP information.
Registration and retrieval of fingerprint information are free of charge.
There are two types of fingerprints:
  1. The debug fingerprint used for development can only be used in your own debug application;
  2. Official fingerprint.
You only need the first one.
The procedure is: first, the development environment should have JDK. Go to the bin directory of JDK and run:

The following code is displayed:

Copy the fingerprint part.
Then visit:
Http://code.google.com/intl/zh-CN/android/add-ons/google-apis/maps-api-signup.html
There is also a premise that you have to have a google account and log on.
Copy the md5 fingerprint to the red box:

Select agree to the agreement.
After submission, you will see:

In fact, it is mainly to get the key in the red box. In the program or layout file, add or set the androidLapiKey attribute where MapView is used.
The code is actually very simple:
Public class LocationActivity extends MapActivity {
Private MapView mapView;
Private MapController mapController;
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
MapView = (MapView) findViewById (R. id. map_view );
Log. I ("welcome", "created map activity .");
}
@ Override
Protected boolean isRouteDisplayed (){
Return false;
}
}
Layout file used:
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical" android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
<Com. google. android. maps. MapView
Android: id = "@ + id/map_view" android: layout_width = "fill_parent"
Android: layout_height = "fill_parent" android: enabled = "true"
Android: clickable = "true" android: apiKey = "xxxxxxxxxxxxxx"/>
</LinearLayout>
 

From the treasure Valley

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.