How to Create a Google Map on Android

Source: Internet
Author: User

Tank teaches you how to make a simple Google map on AndroidProgram

Step 1: Apply for a Google key
1. Find the Debug. keystore path
Myeclipse
Window --> preferences --> Android --> build --> default debug keystore
Default debug keystore = "C: \ Documents ents and Settings \ Administrator \. Android \ Debug. keystore"
CMD:
Keytool-list-alias androiddebugkey-keystore "C: \ Documents and

Settings \ Administrator \. Android \ Debug. keystore"
Input:
Android
The fingerprint 7A: 71: D1: *: EC: 40: *: 18: 52: 0a: 08: B1: 05 :*:*:*

Apply for googel key URL: http://code.google.com/intl/zh-CN/android/add-ons/google-apis/maps-api-

Signup.html. Enter the value and register an account to obtain the key.

Step 2:
Create a project. Note that Google APIs must be selected in build target of the new Android project.

The previous SDK was not fully installed, so there was no Google APIs in build target, which made me annoyed.
If not, reinstall the SDK.

Create a class to inherit from mapactivity

Not to mention the source code:

Package com. Android. Google. tank;

Import java. util. List;

Import Android. Graphics. drawable. drawable;
Import Android. OS. Bundle;
Import Android. View. view;
Import Android. View. View. onclicklistener;
Import Android. widget. Button;

Import com. Google. Android. Maps. geopoint;
Import com. Google. Android. Maps. mapactivity;
Import com. Google. Android. Maps. mapcontroller;
Import com. Google. Android. Maps. mapview;
Import com. Google. Android. Maps. overlay;
Import com. Google. Android. Maps. overlayitem;

Public class mygooglemap extends mapactivity {
Private mapview;
Private mapcontroller MC;

@ Override
Protected Boolean isroutedisplayed (){
// Todo auto-generated method stub
Return false;
}

@ Override
Protected void oncreate (bundle icicle ){
// Todo auto-generated method stub
Super. oncreate (icicle );

Setcontentview (R. layout. Main );


Mapview = (mapview) findviewbyid (R. Id. Map );
Mapview. settraffic (true); // traffic mode
Mapview. setstreetview (false); // Street Mode
Mapview. setsatellite (false); // satellite mode
MC = mapview. getcontroller ();

Geopoint Gp = new geopoint (INT) (31.132259*1000000 ),
(INT) (121.180762*1000000); // geographic coordinate Shanghai
MC. animateto (GP );
MC. setzoom (10); // scaling ratio
// Add scaling event
// Zoom in
Button btnbig = (button) findviewbyid (R. Id. btnbig );
Btnbig. setonclicklistener (New onclicklistener (){

@ Override
Public void onclick (view v ){
// Todo auto-generated method stub
Mapview. getcontroller (). setzoom (mapview. getzoomlevel () + 1 );
}
});
// Zoom out
Button btnsmall = (button) findviewbyid (R. Id. btnsmall );
Btnsmall. setonclicklistener (New onclicklistener (){

@ Override
Public void onclick (view v ){
// Todo auto-generated method stub
Mapview. getcontroller (). setzoom (mapview. getzoomlevel ()-1 );
}
});


}

}





Configure permissions in androidmanifest. xml and Google load packages:

 
   
package = "com. android. google. tank "Android: versioncode =" 1 "
Android: versionname =" 1.0 ">






Android: Label =" mapsdemo ">






in Main. xml:

 
   
Android: Orientation = "vertical" Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
Android: layout_width = "wrap_content" Android: layout_height = "wrap_content">
Android: layout_width = "wrap_content" Android: layout_height = "wrap_content">
Android: layout_width = "wrap_content" Android: layout_height = "wrap_content">

Android: Id = "@ + ID/Map" Android: layout_width = "match_parent"
Android: layout_height = "match_parent" Android: enabled = "true"
Android: clickable = "true" Android: apikey = "Goole key you applied for"/>

OK. Click Run to view the cool Google map!

However, you must be able to connect to the network, and the simulator must be able to access the Internet! The simulator platform should also choose Google API

In the next few articles, I will post the custom tagging feature on Google and how to get the GPS location (longitude and latitude !)

Effect

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.