Android uses Baidu Navigation SDK 2.0 summary

Source: Internet
Author: User

Effect:

Using the Baidu Navigation SDK, the first information to be obtained is:

1. Latitude and longitude of the starting position, place name
2. Longitude and latitude of the end point, place name
3. The type of coordinate system used for the latitude and longitude of the starting point (Coordinatetype)

The parameters are as follows:

private void routeplanToNavi(CoordinateType coType, double startLatitude,            double startLongitude, String startName, double endLatitude,            double endLongitude, String endName) {......}
Ideas:
1.起始点使用当前位置,由定位SDK获取当前位置(使用的坐标系是bd09ll);2.目的地终点,根据用户输入关键字,使用PoiNearbySearchOption结合PoiCitySearchOption转成坐标点(坐标系是bd09ll);3.将以上bd09ll坐标系转成导航2.0支持的BD09_MC,GCJ02,WGS84三者之一。
Implementation: POI Search section:

Set two edittext:

textcity Destination City (empty defaults to current city)
Textwhere Destinations

According to the user's keywords, determine whether to poinearbysearchoption or poicitysearchoption

public void Startsearchplace (String where, Latlng centerlatlng, Boolean isnear) {if (where! = null &amp ;& where. Trim(). Length() >0) {if (-1= = Networkutil. Getnetworktype(Getapplicationcontext ())) {Networkutil. Nonetworkhint(Getapplicationcontext ());} else {String textcity = ethistorycity. GetText(). toString();Boolean isinputcity = textcity! = NULL && textcity. Trim(). Length() >0;if (isnear) {//Around search Toast. Maketext(Getapplicationcontext (), Getresources (). getString(R. String. Poi_search_near) + where, Toast. LENGTH_short). Show();Poinearbysearchoption poioption = new Poinearbysearchoption ();Poioption. Keyword(where);Poioption. location(CENTERLATLNG);Poioption. Radius( the* +* +);//Search radius, unit: MPoioption. SortType(Poisorttype. Distance_from_near_to_far);//Sort by distancePoioption. SortType(Poisorttype. Comprehensive);//Sort by synthesisPoioption. Pagenum(0);//pagination numberPoioption. Pagecapacity(Ten);//set per page capacity, default to 10 per pagetry {Mpoisearch. Searchnearby(poioption);} catch (Exception e) {E. Printstacktrace();}} else {if (!isinputcity) {//Perimeter search Toa St. Maketext(Getapplicationcontext (), Getresources (). getString(R. String. Poi_search_near) + where, Toast. LENGTH_short). Show();Poinearbysearchoption poioption = new Poinearbysearchoption ();Poioption. Keyword(where);Poioption. location(CENTERLATLNG);Poioption. Radius( the* +* +);//Search radius, unit: MPoioption. SortType(Poisorttype. Distance_from_near_to_far);//Sort by distancePoioption. SortType(Poisorttype. Comprehensive); //Sort by synthesis poioption. Pagenum(0);//pagination numberPoioption. Pagecapacity(Ten);//set per page capacity, default to 10 per pagetry {Mpoisearch. Searchnearby(poioption);} catch (Exception e) {E. Printstacktrace();}} else {//National search Toast. Maketext(Getapplicationcontext (), Getresources (). getString(R. String. Poi_in_city) + textcity + getresources (). getString(R. String. Poi_search) + where, Toast. LENGTH_short). Show();Poicitysearchoption poioption = new Poicitysearchoption ();Poioption. City(textcity);Poioption. Keyword(where);Poioption. Pagenum(0);Poioption. Pagecapacity(Ten);Mpoisearch. Searchincity(poioption);}//Store search history to the database, the perimeter does not need int existid = NAVIDB. Getnaviidbykey(where);if (existid! =-1) {NAVIDB. Deletenavihistorybyid(Existid);} navihistory navihistory = new Navihistory (where, textcity);Navidb. Addnavihistory(navihistory);Navihistoryadapter. notifydatasetchanged();}            }        }    }
Coordinate system Transformation:
/** * startLatitude,startLongitude为bd09ll * bdLocStartAfter.getLongitude()和bdLocStartAfter.getLatitude()即为转化过的坐标系 * BDLocation.BDLOCATION_BD09LL_TO_GCJ02表示从bd09ll转成gcj02坐标系 */new BDLocation();        bdLocStartBefore.setLatitude(startLatitude);        bdLocStartBefore.setLongitude(startLongitude);        BDLocation bdLocStartAfter = LocationClient.getBDLocationInCoorType(                bdLocStartBefore, BDLocation.BDLOCATION_BD09LL_TO_GCJ02);
Surrounding and collection

In the navigation based on the implementation of the surrounding search and collection functions:

Implementation method:
1. Use poinearsearch around to obtain latitude and longitude;
2. Collect the map points and then store the latitude and longitude;
3. The following is consistent with the navigation.

Copyright Notice: This article original, reproduced please indicate the source: Http://blog.csdn.net/zhoumushui

Android uses Baidu Navigation SDK 2.0 summary

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.