android--Call Baidu Map API

Source: Internet
Author: User

First apply for a Baidu map of the API KEY, specific methods on-line has, after the application to obtain:

The Main.xml code is as follows:

<linearlayout     xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools "    android:layout_width=" match_parent "    android:layout_height=" Match_parent " >    <com.baidu.mapapi.map.mapview        android:id= "@+id/map_view"        android:layout_width= "Match_ Parent "        android:layout_height=" match_parent "        android:clickable=" true "/></linearlayout>

. Java code is as follows:

Package Com.example.baidumapproject;import Com.baidu.mapapi.sdkinitializer;import Com.baidu.mapapi.map.MapView; Import Android.os.bundle;import Android.support.v7.app.actionbaractivity;public class Mainactivity extends actionbaractivity {private Mapview mapview=null;    @Override    protected void onCreate (Bundle savedinstancestate) {        super.oncreate (savedinstancestate);        Sdkinitializer.initialize (Getapplicationcontext ());        Setcontentview (r.layout.activity_main);        this.mapview= (Mapview) Super.findviewbyid (R.id.map_view);                   }    @Override    protected void OnDestroy () {    Super.ondestroy ();    Mapview.ondestroy ();    }    @Override    protected void Onresume () {    super.onresume ();    Mapview.onresume ();    }    @Override    protected void OnPause () {    super.onpause ();    Mapview.onpause ();    }}


To configure the permissions file:


<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "http://schemas.android.com/apk/res/ Android "package=" Com.example.baidumapproject "android:versioncode=" 1 "android:versionname=" 1.0 "> <uses -SDK android:minsdkversion= "8" android:targetsdkversion= "/> <uses-permission android:name=" Android Oid.permission.GET_ACCOUNTS "/> <uses-permission android:name=" Android.permission.USE_CREDENTIALS "/> < Uses-permission android:name= "Android.permission.MANAGE_ACCOUNTS"/> <uses-permission android:name= " Android.permission.AUTHENTICATE_ACCOUNTS "/> <uses-permission android:name=" android.permission.ACCESS_ Network_state "/> <uses-permission android:name=" Android.permission.INTERNET "/> <uses-permission Android:name= "Com.android.launcher.permission.READ_SETTINGS"/> <uses-permission android:name= " Android.permission.CHANGE_WIFI_STATE "/> <uses-permission android:name=" Android.permissIon. Access_wifi_state "/> <uses-permission android:name=" Android.permission.READ_PHONE_STATE "/> < Uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name= " Android.permission.BROADCAST_STICKY "/> <uses-permission android:name=" Android.permission.WRITE_SETTINGS "/ > <uses-permission android:name= "Android.permission.ACCESS_FINE_LOCATION"/> <application android: Allowbackup= "true" android:icon= "@drawable/ic_launcher" android:label= "@string/app_name" Android:them            E= "@style/apptheme" > <activity android:name= "com.example.baidumapproject.MainActivity" Android:label= "@string/app_name" > <intent-filter> <action android:name= "android.in Tent.action.MAIN "/> <category android:name=" Android.intent.category.LAUNCHER "/> </     Intent-filter> </activity>   <meta-data android:name= "Com.baidu.lbsapi.API_KEY" android:value= "<a target=_blank style=" LI St-style-type:none; Text-decoration:none; White-space:normal; word-spacing:0px; Text-transform:none; Color:rgb (51,51,51); Outline-width:medium; padding-bottom:0px; Text-align:left; padding-top:0px; font:13px/28px Microsoft Black, ' Microsoft Yahei ', Sans-serif; Outline-style:none; padding-left:0px; margin:0px; Letter-spacing:normal; Outline-color:invert; padding-right:0px; Background-color:rgb (248,249,250); text-indent:0px; -webkit-text-stroke-width:0px ">8eo5swqAaq4A2dn2RuwdKa5k</a>"/> </application></manifest >


Run the following example:

android--Call Baidu Map API

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.