Team project: Android using Baidu Map API to locate the runway

Source: Internet
Author: User
Tags sha1

Because Android call API for me is a completely unfamiliar field, I after a long time to finally get out, this period of time is very effective, I got the experience.

First step: Register as Baidu developer

Create an app on the Baidu map open platform. Address http://lbsyun.baidu.com/index.php?title= Home

Find the SHA1 code to register in the computer, look for the way to SHA1 code, there are tutorials online, start I did not use integrated Android Eclipse, with Android studio. So the cmd command station is used to find the way.

This image is excerpted from the Internet

This is another way: open Windows-->preferences-->android-->build in Eclipse

The following is the name of the package created in Eclipse, which is also written to the application; you can get an AK

This is my development application AK:

Download the Android Map SDK again

After downloading the SDK, find Libs to copy the jar files

In Eclipse (before using Android studio to try 5 times, flash back, error, probably I am not familiar with the platform of Android studio. I switched to eclipse, which integrates Android, for development. ), create a new Android project named map.

Create a new LIBS project in your project and paste the jar file into the file. It is then imported into the project, with a small red mark at the bottom left.

In the same vein, all folders containing so files (i.e., Armeabi) are imported into the libs.

Adding Permissions in Androidmenifest.xml

<uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE"/>
<!--access Network--
<uses-permission android:name= "Android.permission.INTERNET"/>
<!--get WiFi status-
<uses-permission android:name= "Android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name= "Android.permission.CHANGE_WIFI_STATE"/>
<!--allows programs to write to external storage, such as writing files on an SD card--
<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name= "Android.permission.WRITE_SETTINGS"/>
<!--read phone status--
<uses-permission android:name= "Android.permission.READ_PHONE_STATE"/>
<uses-permission android:name= "Android.permission.CALL_PHONE"/>
<!--get positioning information for accurate position GPS chip receiving satellite, positioning accuracy up to 10 meters and less
<uses-permission android:name= "Android.permission.ACCESS_FINE_LOCATION"/>
<!--get user-error latitude and longitude information via WiFi or mobile base station--
<uses-permission android:name= "Android.permission.ACCESS_COARSE_LOCATION"/>
<!--get analog positioning information--
<uses-permission android:name= "Android.permission.ACCESS_MOCK_LOCATION"/>
<uses-permission android:name= "Android.permission.ACCESS_GPS"/>

Increase AK

<meta-data              android:name= "Com.baidu.lbsapi.API_KEY"              

Add code to Activity_main.xml

<com.baidu.mapapi.map.mapview         android:id= "@+id/bmapview"         android:layout_width= "Fill_parent         " android:layout_height= "Fill_parent"         android:clickable= "true"/>  

Add the following code to the mainactivity.

Package Com.example.map;import Com.baidu.mapapi.sdkinitializer;import Com.baidu.mapapi.map.mapview;import        Android.os.bundle;import Android.app.activity;import Android.view.menu;public class MainActivity extends Activity {             Mapview Mmapview = null;//The control used to display the map; @Override protected void OnCreate (Bundle savedinstancestate) {          Super.oncreate (savedinstancestate); Sdkinitializer.initialize (Getapplicationcontext ());//Initialize the Map SDK, note must be written in Setcontentview (R.layout.activity_main);                  Before the code; Setcontentview (R.layout.activity_main); Mmapview = (Mapview) Findviewbyid (R.id.bmapview);//Bound control;} @Override protected void OnDestroy () {//Manage map          Life cycle: Destruction of Super.ondestroy ();            Mmapview.ondestroy ();          } @Override protected void Onresume () {//display; Super.onresume ();      Mmapview.onresume ();          } @Override protected void OnPause () {//pause; Super.onpause (); MmapvieW.onpause ();  }    }

  

Run a normal map. Result is

This is my last Children's Day straight at home debugging before the map demo, in the school virtual machine display is a grid diagram, I thought it was because the computer did not show the GPS, the results found there are errors. This is my commissioning of the most of the day, from morning to 2 o'clock in the afternoon, only to run to the phone.

Andriod Studio I tried it 5 times before, and every time there was no error before running, because I thought I had changed the place where the error was shown. The first run reported more than 300 errors, the second error more than 700, I really have no way to adjust. So I switched to eclipse.

This is one of the studio

The next step should be to import the Location SDK reference above into Libs

I made it myself. Because the file size is 33M, it cannot be uploaded to Coding.net. NET Disk Link: Https://pan.baidu.com/s/1bYImiq

To tell the truth, I made a basic map, I found a demo, I put it debugging out, there is positioning function, the effect is very good. is also based on the Eclipse version, is a very good development version. NET Disk Link: Https://pan.baidu.com/s/1qYTgojE

This is where I run the positioning

During this time I borrowed an Android book from the library and looked at the use of Google Maps in studio. In short, hands-on, but also learned a lot of things.

On the postgraduate study of this course, for my own direction is also a great use of software engineering is a very useful course, in short this semester, especially in this course I learned a lot.

Team project: Android using Baidu Map API to locate the runway

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.