Basic Development of Baidu maps and Development of Baidu maps

Source: Internet
Author: User

Basic Development of Baidu maps and Development of Baidu maps

Due to the needs of the project, I recently encountered Baidu map Android development and encountered many problems. I believe many bloggers have encountered these problems. Now I will share my practical experience with you.

To develop Baidu maps, Step 1: first log on to the Baidu map open platform and register a developer identity. With this identity, you can view Baidu's latest development documentation, it facilitates our development. With the developer identity, you can start preparing for developing Baidu maps.

Open the Android development tool and create a development project. Then, you can use your developer identity registered with Baidu to apply for a key. The method for applying for a key is clear in the Baidu document. After two minutes of application, we recommend that you use the latter method. With the key, the following is the Jar package required for development. Download the desired package on the Baidu developer platform.

With the above preparations, we can start development. Open the Android development tool, open the project we just created, and import the downloaded Jar package to the project, note that you also need to add one when importing the Jar package: the armeabi folder contains two libBaiduMapSDK_v3_0_0.so and liblocSDK4d. so must be imported together. Import select project right-click, select properties> Java Build Path> Libraries, click Add External JARS... on the right ..., select the Jar file under the project Libs, and do not forget to select the Jar package under Oreder and Exporxt. Click OK to complete the environment configuration.

The following is the code. First, the AndroidManifest. xml file:

Get permission:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" >    </uses-permission>    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" >    </uses-permission>    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" >    </uses-permission>    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" >    </uses-permission>    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" >    </uses-permission>    <uses-permission android:name="android.permission.READ_PHONE_STATE" >    </uses-permission>    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" >    </uses-permission>    <uses-permission android:name="android.permission.INTERNET" />    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" >    </uses-permission>    <uses-permission android:name="android.permission.READ_LOGS" >    </uses-permission>    <uses-permission android:name="android.permission.VIBRATE" />    <uses-permission android:name="android.permission.WAKE_LOCK" />    <uses-permission android:name="android.permission.WRITE_SETTINGS" />

 

Set key

 

// Add it to the application
<Meta-data android: name = "com. baidu. lbsapi. API_KEY "android: value =" Key number "/> <service android: name =" com. example. baidumap_01 "android: enabled =" true "android: process =": remote "> <intent-filter> <action android: name =" com. baidu. location. service_v2.2 "> </action> </intent-filter> </service>

 

Layout file activity_main.xml:

<RelativeLayout 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"    tools:context="${relativePackage}.${activityClass}" >    <com.baidu.mapapi.map.MapView        android:id="@+id/id_bmapView"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:clickable="true" /></RelativeLayout>

Main file MainActivity. java file:

Package com. example. baidumap_01; import com. baidu. mapapi. SDKInitializer; import com. baidu. mapapi. map. baiduMap; import com. baidu. mapapi. map. mapView; import android. app. activity; import android. OS. bundle; import android. view. window; public class MainActivity extends Activity {private MapView mMapView = null; private BaiduMap mBaiduMap = null; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); requestWindowFeature (Window. FEATURE_NO_TITLE); // initialize the context information before using the SDK components, and pass in the ApplicationContext // note that this method must be implemented before the setContentView method. initialize (getApplicationContext (); setContentView (R. layout. activity_main); // obtain the map control reference mMapView = (MapView) findViewById (R. id. id_bmapView); mBaiduMap = mMapView. getMap (); // normal map // mBaiduMap. setMapType (BaiduMap. MAP_TYPE_NORMAL); // satellite map mBaiduMap. setMapType (BaiduMap. MAP_TYPE_SATELLITE) ;}@ Override protected void onDestroy () {super. onDestroy (); // execute mMapView when onDestroy is executed in activity. onDestroy () to implement mMapView for map lifecycle management. onDestroy () ;}@ Override protected void onResume () {super. onResume (); // execute mMapView when onResume is executed in the activity. onResume () to implement mMapView for map lifecycle management. onResume () ;}@ Override protected void onPause () {super. onPause (); // execute mMapView when onPause is executed in activity. onPause () enables mMapView for map lifecycle management. onPause ();}}

Effect after running:

The above is the development Introduction of Baidu map V3.0. If you are interested, you can leave a message.

 

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.