Go to the android project of mobile development (Baidu map: how to convert longitude and latitude)

Source: Internet
Author: User

Please note that when reprinting an article, please indicate the source.

Http://blog.csdn.net/shuaiyinoo》thank you

Today is an update of the last blog on Baidu map. I have read the previous blogs and I don't know how you feel or understand them, the query methods provided by the Basic Baidu map are basically called asynchronously. the asynchronous call is displayed in the methods of mysearchlistener implements mksearchlistener that implement this interface.


Of course, this query and conversion of longitude and latitude are also experienced here. During the conversion of latitude and longitude, you only need to call the following two methods of Baidu map, then you can know how to convert the longitude and latitude.



In general, Baidu map is easier to do than Google map APIs, probably because Baidu map APIs are made in Chinese, and the APIS developed by Chinese people are more suitable for Chinese users, the success is for everyone. Next I will post the core code of these blogs for your reference.


Then, we will attach the overall projects of these blogs. Please laugh at the shortcomings and include them ......

--- >>> Direct flights to source code download locations


Package COM. shuaiyin. baidu; import Java. util. arraylist; import Java. util. list; import android. content. context; import android. graphics. canvas; import android. graphics. paint; import android. graphics. point; import android. graphics. drawable. drawable; import android. OS. bundle; import android. widget. toast; import COM. baidu. mapapi. bmapmanager; import COM. baidu. mapapi. geopoint; import COM. baidu. mapapi. itemizedoverla Y; import COM. baidu. mapapi. mkaddrinfo; import COM. baidu. mapapi. mkbuslineresult; import COM. baidu. mapapi. mkdrivingrouteresult; import COM. baidu. mapapi. mkgenerallistener; import COM. baidu. mapapi. mkplannode; import COM. baidu. mapapi. mkpoiinfo; import COM. baidu. mapapi. mkpoiresult; import COM. baidu. mapapi. mksearch; import COM. baidu. mapapi. mksearchlistener; import COM. baidu. mapapi. mksuggestionresult; import COM. bai Du. mapapi. mktransitrouteresult; import COM. baidu. mapapi. mkwalkingrouteresult; import COM. baidu. mapapi. mapactivity; import COM. baidu. mapapi. mapcontroller; import COM. baidu. mapapi. mapview; import COM. baidu. mapapi. overlay; import COM. baidu. mapapi. overlayitem; import COM. baidu. mapapi. routeoverlay; import COM. baidu. mapapi. transitoverlay;/*** allow Baidu map to inherit mapactivity * @ author shuaiyin **/public class baidu_suyiact Ivity extends mapactivity {// Add the control private mapview related to Baidu map; // The Private bmapmanager caused by Baidu map loading; // define Baidu map's keyprivate string key = "3da88729dd94b0429a4bee30797e04d91b0211c4"; // Add the corresponding control private mapcontroller on Baidu map; // define the search object private mksearch; // define a start point private mkplannode start; // define an end point private mkplannode end; @ override public void oncreate (bundle savedinstancestate) {super. Oncreate (savedinstancestate); setcontentview (R. layout. main); // first instantiate mapview = (mapview) This. findviewbyid (R. id. bmapview); bmapmanager = new bmapmanager (baidu_suyiactivity.this); // call Baidu map to load key bmapmanager. init (Key, new mkgenerallistener () {@ overridepublic void ongetpermissionstate (INT arg0) {If (arg0 = 300) {toast. maketext (baidu_suyiactivity.this, "the key you entered is incorrect. Please verify", 2 ). show () ;}@ overridepubli C void ongetnetworkstate (INT arg0) {}}); this. initmapactivity (bmapmanager); // indicates that the zoom function mapview can be set. setbuiltinzoomcontrols (true); mapcontroller = mapview. getcontroller (); // v1.00 // mark a central point on Baidu map // geopoint = new geopoint (INT) (39.915*1e6), (INT) (116.404*1e6); // set a central point for the map object // mapcontroller. setcenter (geopoint); // set the map zoom level // mapcontroller. setzoom (12); // display the traffic map // mapview. settraffic (true); // display Satellite map // mapview. setsatellite (true); // v2.00 // set the annotation for the map object // mapview. getoverlays (). add (New myoverlay (); // mapcontroller. setzoom (12); // v3.00 // set multiple annotators for the map // display the annotator icon // drawable = getresources (). getdrawable (R. drawable. iconmarka); // mapview. getoverlays (). add (New myoverlayitem (drawable); // v4.00 // mapcontroller. setzoom (14); // search for objects within the MAP range // mksearch = new mksearch (); // mksearch. init (bmapmanag Er, new mysearchlistener (); // This method searches the surrounding content based on the central point. // mksearch. earchnearby ("restroom", new geopoint (INT) (39.915*1e6), (INT) (116.404*1e6), 5000 ); // search for the v5.00 driving route // mapcontroller. setzoom (14); // search for objects within the MAP range // mksearch = new mksearch (); // mksearch. init (bmapmanager, new mysearchlistener (); // specify the first coordinate // start = new mkplannode (); // start.pt = new geopoint (INT) (39.915*1e6), (INT) (116.404*1e6); // specify the Second coordinate/ /End = new mkplannode (); // end.pt = new geopoint (40057031,2017307852); // route priority // mksearch. setdrivingpolicy (mksearch. ebus_time_first); // call the callback method of the route // mksearch. drivingsearch (null, start, null, end); // 6.0 Route Search // mapcontroller. setzoom (12); // search for objects within the MAP range // mksearch = new mksearch (); // mksearch. init (bmapmanager, new mysearchlistener (); // specify the first coordinate. // start = new mkplannode (); // start.pt = new geopoi NT (INT) (39.915*1e6), (INT) (116.404*1e6); // specify the Second coordinate // end = new mkplannode (); // end.pt = new geopoint (40057031,2017307852); // method for setting the callback route // mksearch. walkingsearch (null, start, null, end); // search for the 7.0 bus transfer route // mapcontroller. setzoom (12); // search for objects within the MAP range // mksearch = new mksearch (); // mksearch. init (bmapmanager, new mysearchlistener (); // specify the first coordinate // start = new mkplannode (); // start.pt = new geopoint (int) (39.915*1e6), (INT) (116.404*1e6); // specify the Second coordinate // end = new mkplannode (); // end.pt = new geopoint (40057031,2017307852); // method for setting the callback route // mksearch. transitsearch ("Beijing", start, end); // 8.0 search for the bus route details // mapcontroller. setzoom (12); // search for objects within the MAP range // mksearch = new mksearch (); // mksearch. init (bmapmanager, new mysearchlistener (); // method for setting the callback route // mksearch. poisearchincity ("Beijing", "300"); // search mapcontro for Multiple Route entries at v9.00 Roller. setzoom (14); // search for objects within the MAP range mksearch = new mksearch (); mksearch. init (bmapmanager, new mysearchlistener (); // specify the first coordinate start = new mkplannode (); start.pt = new geopoint (INT) (39.915*1e6), (INT) (116.404*1e6); // specify the Second coordinate end = new mkplannode (); end.pt = new geopoint (40057031,2017307852); // call the route callback method mksearch. transitsearch ("Beijing", start, end);} // public class mysearchlistener implements mks Earchlistener {// obtain the latitude and longitude @ overridepublic void ongetaddrresult (mkaddrinfo res, int error) {If (error! = 0) {toast. maketext (baidu_suyiactivity.this, "sorry, you cannot find the result", 2 ). show (); return;} mapview. getcontroller (). animateto (res. geopt); string MSG = string. valueof (res. geopt. getlatitudee6 ()/1e6) + String. valueof (res. geopt. getlongitudee6 ()/1e6); drawable = getresources (). getdrawable (R. drawable. iconmarka); mapview. getoverlays (). clear () ;}@ overridepublic void ongetbusdetailresult (mkbuslineresult result, int ty PE) {If (result = NULL | type! = 0) {toast. maketext (baidu_suyiactivity.this, "sorry, you cannot find the result", 2 ). show (); return;} routeoverlay = new routeoverlay (baidu_suyiactivity.this, mapview); routeoverlay. setdata (result. getbusroute (); // clear all bus information mapview. getoverlays (). clear (); mapview. getoverlays (). add (routeoverlay); mapview. invalidate (); mapview. getcontroller (). animateto (result. getbusroute (). getstart () ;}@ overridepublic void ongetdrivi Ngrouteresult (mkdrivingrouteresult result, int type) {// callback response to the called search method if (result = NULL) {return;} routeoverlay = new routeoverlay (baidu_suyiactivity.this, mapview); // The reason for entering 0 is that we only need to return the first line routeoverlay. setdata (result. getplan (0 ). getroute (0); mapview. getoverlays (). add (routeoverlay); mapview. invalidate () ;}@ overridepublic void ongetpoidetailsearchresult (INT result, int type) {}@ overridepu BLIC void ongetpoiresult (mkpoiresult result, int type, int ierror) {// callback response to the called search method // v3.00 // If (result = NULL) {// return; // poioverlay = new poioverlay (baidu_suyiactivity.this, mapview); // poioverlay. setdata (result. getallpoi (); // mapview. getoverlays (). add (poioverlay); // mapview. invalidate (); // v8.00if (result = NULL | ierror! = 0) {toast. maketext (baidu_suyiactivity.this, "sorry, you cannot find the result", 2 ). show (); Return ;}// define a bus route map description class mkpoiinfo = NULL; // get the bus route map's total site int totalpoinum = result. getnumpois (); For (INT I = 0; I <totalpoinum; I ++) {mkpoiinfo = result. getpoi (I); If (mkpoiinfo. epoitype = 2) {break; // if the road map of the bus is returned, return} mksearch. buslinesearch ("Beijing", mkpoiinfo. UID) ;}@ overridepublic void ongetrgcshareurlresult (string arg0, int arg1 ){} @ Overridepublic void ongetsuggestionresult (mksuggestionresult arg0, int arg1) {}@ overridepublic void ongettransitrouteresult (mktransitrouteresult result, int type) {// callback Method for Public Transit transfer // v7.00 // If (result = NULL) {// return; //} // transitoverlay = new transitoverlay (baidu_suyiactivity.this, mapview); // transitoverlay. setdata (result. getplan (0); // mapview. getoverlays (). add (transitoverlay); // refresh the map // Mapview. invalidate (); // v9.00if (result = NULL) {return ;}// obtain all driving routes. Int plannum = result. getnumplan (); For (INT I = 0; I <plannum; I ++) {transitoverlay = new transitoverlay (baidu_suyiactivity.this, mapview); transitoverlay. setdata (result. getplan (I); mapview. getoverlays (). add (transitoverlay);} mapview. invalidate (); mapview. getcontroller (). animateto (result. getstart (). pt) ;}@ overridepublic void Ongetwalkingrouteresult (mkwalkingrouteresult result, int type) {// callback response to the called search method if (result = NULL) {return;} routeoverlay = new routeoverlay (baidu_suyiactivity.this, mapview); routeoverlay. setdata (result. getplan (0 ). getroute (0); mapview. getoverlays (). add (routeoverlay); // refresh the map mapview. invalidate () ;}}// mark a shelter public class myoverlay extends overlay {// declare a location private geopoint = new Geopoint (INT) (39.915*1e6), (INT) (116.404*1e6); // declare a paint brush tool private paint = new paint (); @ override public void draw (canvas arg0, mapview arg1, Boolean arg2) {super. draw (arg0, arg1, arg2); point = mapview. getprojection (). topixels (geopoint, null); arg0.drawtext ("here is Tiananmen Square", point. x, point. y, paint) ;}/// multiple concealer public class myoverlayitem extends itemizedoverlay <overlayitem> {private list <ov Erlayitem> overlayitem = new arraylist <overlayitem> (); // defines a set of coordinates: Private double mlat1 = 39.90923; // The private double mlot1 = 116.397428; // weft private double mlat2 = 39.92923; // The value of the private double mlot2 = 116.377428; // The value of the private double mlat3 = 39.94923; // The value of the private double mlot3 = 116.357428; // weft private double mlat4 = 39.96923; // the value of private double mlot4 = 116.337428; // latitude // identifies coordinates on the map and marks public myoverlayitem with an image (Drawable) {super (drawable); geopoint geopoint1 = new geopoint (INT) (mlat1 * 1e6), (INT) (mlot1*1e6 )); geopoint geopoint2 = new geopoint (INT) (mlat2 * 1e6), (INT) (mlot2 * 1e6); geopoint geopoint3 = new geopoint (INT) (mlat3*1e6 ), (INT) (mlot3 * 1e6); geopoint geopoint4 = new geopoint (INT) (mlat4 * 1e6), (INT) (mlot4 * 1e6); overlayitem. add (New overlayitem (geopoint1, "A", "This is the first"); overlayitem. add (New overlayit EM (geopoint2, "B", "this is the second"); overlayitem. add (New overlayitem (geopoint3, "C", "this is the third"); overlayitem. add (New overlayitem (geopoint4, "D", "this is the fourth"); // refresh the map populate ();} // return each coordinate in the specified list set @ overrideprotected overlayitem createitem (INT arg0) {return overlayitem. get (arg0) ;}@ overridepublic int size () {return overlayitem. size () ;}// when the annotation is clicked @ overridepublic Boolean ONTAP (int I) {toast. maketext (baidu_suyiacti Invalid. this, overlayitem. get (I ). getsnippet (), 2 ). show (); Return true ;}}@ override protected void ondestroy () {super. ondestroy (); If (bmapmanager! = NULL) {bmapmanager. Destroy (); bmapmanager = NULL ;}@override protected void onresume () {super. onresume (); If (bmapmanager! = NULL) {bmapmanager. Start () ;}@ override protected void onpause () {super. onpause (); If (bmapmanager! = NULL) {bmapmanager. Stop () ;}@ overrideprotected Boolean isroutedisplayed () {return false ;}}


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.