Simple android Application Development Based on Google Map (illustration)

Source: Internet
Author: User
Tags android sdk manager

I. Preparations

1. Apply for the Android Map API Key

Prerequisites: Your google account and System Certificate.

First find our debug. keystore file. If you have installed eclipse and configured the android development environment (the Environment configuration is no longer repeated here, the previous blog provides detailed instructions ), you can use Window-> Preference-> Android-> Build. We can see that the Default debug keystore is debug. the keystore path.




 

Next we need to obtain the MD5 value, open the command line, and go to debug. in the directory where the keystore is located, run the command keytool-list-keystore debug. keystore. Here, you will be asked to enter the keystore password. The default value is android.





 

Next, we need to apply for the Android Map API Key and open the URL "primary Key.





 

1. Create an AVD Based on Google APIs

Window-> AVD Manager-> new, enter the AVD name, and select Google APIs in Target.



 

Note that if the Target option does not contain the Google APIs option, install Google APIs in the Android SDK Manager.





 

1. Create a simple GoogleAPIs-based application

1. Create a new project

Just like creating a common android app, File-> new-> other-> Android Project. we name the Project googleMapApp. Note that, select Google APIs when selecting Target.




 

1. Necessary modifications

Open the AndroidManifest. xml file. To use Google Map APIs, you must define the following sentence:

<Uses-libraryandroid: name = "com. google. android. maps"/>

Because we still need to use the network, we need to add a network access license <uses-permissionandroid: name = "android. permission. INTERNET "/>, if you do not add a network license, the application will not display a map, only display grid lines.

The following code adds the MapView attribute to the layout file main. xml:

 


[Html] <com. google. android. maps. MapView
Android: id = "@ + id/mapView"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: apiKey = "0DXjJ7k6Ul6gx2s4aQEbs8Chg43eW-dVeowPqIQ"
/>
<Com. google. android. maps. MapView
Android: id = "@ + id/mapView"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: apiKey = "0DXjJ7k6Ul6gx2s4aQEbs8Chg43eW-dVeowPqIQ"
/>

 

 

Android: apiKey indicates the API Key generated by MD5 when logging on to the google account. Do not confuse it with MD5 here!

GoogleMapAppActivity must inherit MapActivity rather than Activity. The Code is as follows:

 


[Java] public class GoogleMapAppActivity extends MapActivity {
Public MapView mapView;
Public MapController mapController;
Public GeoPoint geoPoint;
/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );

MapView = (MapView) findViewById (R. id. mapView );
MapView. setTraffic (true); // set it to traffic mode
MapView. setClickable (true );
MapView. setBuiltInZoomControls (true); // You can scale the settings.

MapController = mapView. getController ();
GeoPoint = new GeoPoint (int) 40.38014*1000000, (int) 117.00021*1000000); // set the starting point to be near Beijing
MapController. animateTo (geoPoint); // go to Beijing
MapController. setZoom (12 );
}
 
@ Override
Protected boolean isRouteDisplayed (){
Return false;
}
 

 



From pku_android
 

 


 

Related Article

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.