Navigation article Gao De and Baidu

Source: Internet
Author: User
Tags sha1

(a) Baidu Navigation SDK (ie, the app's internal navigation function):

Here are a few steps to be aware of:
1. If the map, location function is included, the jar with integrated function is required
Http://lbsyun.baidu.com/sdk/download?selected=navifunctionwithtts

2. When applying for Baidu Key, fill in the correct (debug and release) SHA1 value, Http://lbsyun.baidu.com/apiconsole/key
(PS:SHA1 value and MD5 value problem, reference http://blog.csdn.net/hexingen/article/details/51799515)

3. Complete the TTS whitelist (this step is not ready, will cause navigation without sound)
Http://app.navi.baidu.com/ttsregister/create

4. Other steps are relatively straightforward to follow in the development guide: http://lbsyun.baidu.com/index.php?title=android-navsdk/guide/introduction

5. The Baidu Navigation SDK under the Spit slot:
Development tools: Android Studio 2.1
Problem Description:

Running above the 5.0 system will result in no problem finding classnotfoundexception  
   (or java.lang.ClassNotFoundException:Didn ' t find class " Com.gos.navi.BNGuideActivity "on Path:dexpathlist[[zip file"/data/app/com.gos.navi-2/base.apk "). Running on a
  5.0-system phone is no problem, it's a wonderful thing.
  There are also professionals who have answered this question: Baidu Engineer, proposed to close as the instant run processing method, and then eggs  

The most amazing thing is that running a project on Eclipse is no problem .

(b) Call Baidu Map client navigation:

demand: Call Baidu Map Navigation, users choose their own navigation
Solution: Call Baidu Map route planning, and then navigate: Baidumaprouteplan.openbaidumapdrivingroute (routeparaoption, context);

protected void Openbaidunavi () {
        latlng startlatlng = null, ENDLATLNG = NULL;
        STARTLATLNG = new Latlng (Baseapplication.getcontext (). Latitude,
                baseapplication.getcontext (). longtitude);
        ENDLATLNG = new Latlng (taglatitude, taglongtitude);
        Routeparaoption routeparaoption = new Routeparaoption ();
        Routeparaoption.startpoint (STARTLATLNG);
        Routeparaoption.endpoint (ENDLATLNG);
        try {
            Baidumaprouteplan
                    . Openbaidumapdrivingroute (routeparaoption, context);
        } catch ( Baidumapappnotsupportnaviexception e) {
            e.printstacktrace ();
             Showtoast ("Please install Baidu map");
        }
    }

(iii) Call the German map client navigation:

Requirements: Call the German map for route planning Navigation
Solution: First convert Baidu map coordinates to the German map coordinates, then the route planning navigation

       protected void Openamapnavi () {//convert first to the coordinates of the high-de map com.amap.api.maps.model.LatLng taglatlng = Converter
        (New Com.amap.api.maps.model.LatLng (Taglatitude, taglongtitude)); Com.amap.api.maps.model.LatLng STARTLATLNG = Converter (New Com.amap.api.maps.model.LatLng (baseapplication
        . GetContext (). Latitude, Baseapplication.getcontext (). longtitude));
            try {Routepara Routepara = new Routepara ();
            Note: The following parameters are required, look at the code in its jar, and find that one less parameter will give you the illegal parameter routepara.setstartpoint (STARTLATLNG);
            Routepara.setendpoint (TAGLATLNG);
            Routepara.setendname (Tagadres);
            Routepara.setstartname (Baseapplication.getcontext (). address);
        Amaputils.openamapdrivingroute (Routepara, Baseapplication.getcontext ());
             } catch (Com.amap.api.maps.AMapException e) {e.printstacktrace ();
        Showtoast ("Please install the German map"); /*//If not installed, it will enterException, adjust download page//Amaputils.getlatestamapapp (Getapplicationcontext ());
        */} catch (Exception e) {e.printstacktrace ();
        }} public Com.amap.api.maps.model.LatLng Converter (Com.amap.api.maps.model.LatLng sourcelatlng) {
        Coordinateconverter converter = new Coordinateconverter (context);
        Converter.from (Coordtype.baidu);
        Converter.coord (SOURCELATLNG);
    return Converter.convert (); }

(four) complete case: Integrated Baidu navigation, gold navigation example
will be the German, Baidu map navigation function encapsulated in dialog, the code is as follows:
1. Corresponding XML:

    <relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "match_parent
        "Android:layout_height=" match_parent "android:background=" @android: Color/transparent "> <textview Android:id= "@+id/select_navi_top_title" android:layout_width= "Match_parent" android:layout_marginright = "10DP" android:layout_height= "wrap_content" android:layout_margintop= "10DP" android:background= "@ Drawable/shape_select_navi_top "android:text=" select Map "android:textcolor=" @color/white "android:layou T_alignparenttop= "true" android:gravity= "center" android:textsize= "18SP" android:textstyle= "bold"
        /> <imageview android:id= "@+id/select_navi_to_cacle_iv" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_alignparentright= "true" android:adjustviewbounds= "True" android:src= "@drawable/navi_close"/> <relativelayout android:layout_width= "Match_parent" Android:layout_h
        eight= "Wrap_content" android:layout_below= "@+id/select_navi_top_title" android:layout_marginright= "10DP" android:background= "@drawable/shape_select_navi_content" > <textview android:id= "@+id/se
            Lect_navi_tip "android:layout_width=" match_parent "android:layout_height=" Wrap_content " android:text= "Choose your favorite Map" android:textcolor= "#999999" android:paddingtop= "10DP" Androi D:paddingbottom= "10DP" android:gravity= "center"/> <linearlayout Android:layout_wid Th= "Match_parent" android:layout_height= "wrap_content" android:paddingbottom= "10DP" an
                droid:paddingtop= "10DP" android:layout_below= "@+id/select_navi_tip" > <relativelayout Android:layouT_width= "0DP" android:layout_weight= "1" android:layout_height= "Wrap_content" > <imageview android:id= "@+id/select_baidu_navi_iv" android:layout_width = "Wrap_content" android:layout_height= "Wrap_content" Android:layout_centerhorizont
                    Al= "true" android:src= "@drawable/baidumap_navi"/> <textview Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" Android 
                    : text= "Baidu map" android:layout_margintop= "5DP" android:layout_centerhorizontal= "true"
            android:layout_below= "@+id/select_baidu_navi_iv" android:textsize= "18sp"/>
                </RelativeLayout> <relativelayout android:layout_width= "0DP" Android:layout_weight= "1" android:layout_height= "wrap_content" android:gravity= "Center" > & Lt;imageview android:id= "@+id/select_amap_navi_iv" android:layout_width= "Wrap_cont
                    Ent "android:layout_height=" wrap_content "android:src=" @drawable/amap_navi " Android:layout_centerhorizontal= "true"/> <textview android:layou
                    T_width= "Wrap_content" android:layout_height= "Wrap_content" android:text= "German map"
                    android:layout_margintop= "5DP" android:layout_centerhorizontal= "true" android:layout_below= "@+id/select_amap_navi_iv" android:textsize= "18sp"/> </r elativelayout> </LinearLayout> </RelativeLayout> </RelativeLayout>

2. The code is as follows:

public class Selectmapnavidialog extends Alertdialog implements Android.view.View.OnClickListener {private Vi
    EW Rootview;
    Private context context;
    Private ImageView Mapnavi_iv, Amapnavi_iv, Close_iv;
    Private double taglatitude, taglongtitude;

    Private String tagadres;
        Public Selectmapnavidialog (context context, double taglatitude, double taglongtitude, String tagadres) {
        Super (context);
        This.context = context;
        This.tagadres = Tagadres;
        This.taglatitude = Taglatitude;
    This.taglongtitude = Taglongtitude;
        } @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
        This.getwindow (). GetAttributes (). Gravity = Gravity.center;
        This.getwindow (). GetAttributes (). Width = (baseapplication.getcontext (). Getwidthpixels ()/5) * 4;

        This.setcanceledontouchoutside (FALSE);
    Initview (); } private void INITView () {Rootview = View.inflate (context, R.layout.dialog_select_navi, null);
        Mapnavi_iv = (ImageView) rootview. Findviewbyid (R.ID.SELECT_BAIDU_NAVI_IV);
        Close_iv = (ImageView) rootview. Findviewbyid (R.ID.SELECT_NAVI_TO_CACLE_IV);
        Amapnavi_iv = (ImageView) rootview. Findviewbyid (R.ID.SELECT_AMAP_NAVI_IV);
        Close_iv.setonclicklistener (this);
        Mapnavi_iv.setonclicklistener (this);
        Amapnavi_iv.setonclicklistener (this);

    This.setcontentview (Rootview);
        } protected void Openbaidunavi () {latlng startlatlng = null, ENDLATLNG = NULL;
        STARTLATLNG = new Latlng (Baseapplication.getcontext (). Latitude, Baseapplication.getcontext (). longtitude);
        ENDLATLNG = new Latlng (taglatitude, taglongtitude);
        Routeparaoption routeparaoption = new Routeparaoption ();
        Routeparaoption.startpoint (STARTLATLNG); Routeparaoption.endpoint (EndLATLNG);
        try {Baidumaprouteplan. Openbaidumapdrivingroute (routeparaoption, context);
             } catch (Baidumapappnotsupportnaviexception e) {e.printstacktrace ();
        Showtoast ("Please install Baidu map");
  }} public void Showtoast (String s) {myutils.showtoast (s); } protected void Openamapnavi () {//convert first to the coordinates com.amap.api.maps.model.LatLng TAGLATLNG = converter (
        New Com.amap.api.maps.model.LatLng (Taglatitude, taglongtitude)); Com.amap.api.maps.model.LatLng STARTLATLNG = Converter (New Com.amap.api.maps.model.LatLng (baseapplication
        . GetContext (). Latitude, Baseapplication.getcontext (). longtitude));
            try {Routepara Routepara = new Routepara ();
            Routepara.setstartpoint (STARTLATLNG);
            Routepara.setendpoint (TAGLATLNG);
            Routepara.setendname (Tagadres); Routepara.setstartname (BaseapplicatIon.getcontext (). address);
        Amaputils.openamapdrivingroute (Routepara, Baseapplication.getcontext ());
             } catch (Com.amap.api.maps.AMapException e) {e.printstacktrace ();
        Showtoast ("Please install the German map");
/*//If no installation will enter the exception, set up the download page//Amaputils.getlatestamapapp (Getapplicationcontext ());
        */} catch (Exception e) {e.printstacktrace ();
        }} public Com.amap.api.maps.model.LatLng Converter (Com.amap.api.maps.model.LatLng sourcelatlng) {
        Coordinateconverter converter = new Coordinateconverter (context);
        Converter.from (Coordtype.baidu);
        Converter.coord (SOURCELATLNG);
    return Converter.convert (); } @Override public void OnClick (view view) {switch (View.getid ()) {R.id.select_baidu_nav
            I_iv:openbaidunavi ();
            This.dismiss ();
        Break Case R.id.select_amap_navi_iv:opEnamapnavi ();
            This.dismiss ();
        Break
            Case R.id.select_navi_to_cacle_iv:this.dismiss ();
        Break
        Default:break; }

    }

}

(v) To resolve the conflict between Baidu Map and the German map:

Issue: 
      Error generating Final archive:found duplicate file for apk:assets/linedashtexture.png
  reason:
       Import outsourcing contains two identical linedashtexture.png files, resulting in conflict
  resolution:
       with the Jar tool (WinRaR), open and then delete the Linedashtexture.png
      (PS: Because the high-D map in this project only needs to call the navigation function, so delete the top-level map jar of duplicate files)

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.