<span id="Label3"></p><p><p><span style="font-size:24px">Previously wrote a android-baidu map call (retrieval Function) is because my Company's project useful to something, made some simple to share.</span><span style="font-weight:bold"><span style="font-size:18px"><span style="white-space:pre"></span></span></span></p></p><p><p><span style="font-size:14px">This article is also a simple introduction of the Baidu Map of the basic map use<br>Now the Android SDK version provided by the Baidu developer Platform Is-android SDK V 3.4.0.</span><br></p></p><p><p><span style="font-size:14px">1, What is the Baidu map Android SDK? (simple look from the official Website)<br></span></p></p><p><p><span style="font-size:14px"><br></span></p></p><p><p><br></p></p><p><p><span style="font-size:14px">2. How to get the customized Baidu map Sdk.<br>The developer can download the download page of the Baidu Maps Android SDK to the latest version of the map sdk,</span><br></p></p><p><p><span style="font-size:14px"><span style="color:rgb(98,98,98); font-family:微软雅黑; font-size:14px; line-height:20px">is:</span>Http://developer.baidu.com/map/index.php?title=androidsdk/sdkandev-download<br></span></p></p><p><p><span style="font-size:14px">3. Basic MAP.</span><br></p></p><p><p><span style="font-size:14px"><br></span></p></p><p><p><span style="font-size:14px">one, Show hundred Map<br>Baidu Map SDK for developers to provide a convenient display of Baidu map data interface, through the following steps, you can use the Baidu map data in your application:<br>The first step: create and configure the project (see the project configuration section for details);<br>The second step: add the development key, the required permission and other information in the androidmanifest;</span><br></p></p><p><p><span style="font-size:14px">1) Add the development key in the application<br></span></p></p><p><p><span style="font-size:14px"></span></p></p><pre code_snippet_id="672779" snippet_file_name="blog_20150522_1_8410733" name="code" class="java"><pre code_snippet_id="672779" snippet_file_name="blog_20150522_1_8410733" name="code" class="java"><application> <meta-data android:name= "com.baidu.lbsapi.API_KEY" android:value= "developer KEY"/ > </application></pre></pre><p><p></p></p><p><p><span style="font-size:14px"><br></span></p></p><pre code_snippet_id="672779" snippet_file_name="blog_20150522_2_3889520" name="code" class="java"><pre code_snippet_id="672779" snippet_file_name="blog_20150522_2_3889520" name="code" class="java">2) Add the required permissions</pre></pre><pre code_snippet_id="672779" snippet_file_name="blog_20150522_2_3889520" name="code" class="java"><uses-permission android:name= "android.permission.GET_ACCOUNTS"/> <uses-permission android:name= " Android.permission.USE_CREDENTIALS "/> <uses-permission android:name=" Android.permission.MANAGE_ACCOUNTS "/ > <uses-permission android:name= "android.permission.AUTHENTICATE_ACCOUNTS"/> <uses-permission android: Name= "android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name= " Android.permission.INTERNET "/> <uses-permission android:name=" com.android.launcher.permission.READ_ SETTINGS "/> <uses-permission android:name=" Android.permission.CHANGE_WIFI_STATE "/> <uses-permission Android:name= "android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name= " Android.permission.READ_PHONE_STATE "/> <uses-permission android:name=" android.permission.WRITE_EXTERNAL_ STORAGE "/> <uses-permission android:name=" Android.permission.BROADCAST_STICKY "/> <uses-permission Android:name= "android.permissioN.write_settings "/> </pre><span style="color:rgb(98,98,98); font-family:微软雅黑; font-size:14px; line-height:20px"><span style="color:rgb(98,98,98); font-family:微软雅黑; font-size:14px; line-height:20px">The third step is to add a map control to the layout XML file; <span style="white-space:pre"></span> </span></span><p><p></p></p><p style="font-family:微软雅黑; padding:0px 15px; margin-top:6px; margin-bottom:6px; color:rgb(98,98,98); font-size:14px; line-height:20px"><p style="font-family:微软雅黑; padding:0px 15px; margin-top:6px; margin-bottom:6px; color:rgb(98,98,98); font-size:14px; line-height:20px"><span style="white-space:pre"><span style="white-space:pre"><span style="color:rgb(98,98,98); font-family:微软雅黑; font-size:14px; line-height:20px"></span></span></span></p></p><pre code_snippet_id="672779" snippet_file_name="blog_20150522_3_5190828" name="code" class="java"><pre code_snippet_id="672779" snippet_file_name="blog_20150522_3_5190828" name="code" class="java"><com.baidu.mapapi.map.mapview android:id= "@+id/bmapview" android:layout_width= "fill_parent " android:layout_height= "fill_parent" android:clickable= "true"/></pre></pre><span style="color:rgb(98,98,98); font-family:微软雅黑; font-size:14px; line-height:20px">the <span style="color:rgb(98,98,98); font-family:微软雅黑; font-size:14px; line-height:20px">Fourth step is to initialize the context global variables referenced by the SDK when the application is Created:</span></span><p><p></p></p><p style="font-family:微软雅黑; padding:0px 15px; margin-top:6px; margin-bottom:6px; color:rgb(98,98,98); font-size:14px; line-height:20px"><p style="font-family:微软雅黑; padding:0px 15px; margin-top:6px; margin-bottom:6px; color:rgb(98,98,98); font-size:14px; line-height:20px"><span style="white-space:pre"><span style="white-space:pre"><span style="color:rgb(98,98,98); font-family:微软雅黑; font-size:14px; line-height:20px"></span></span></span></p></p><pre code_snippet_id="672779" snippet_file_name="blog_20150522_4_2588442" name="code" class="java"><pre code_snippet_id="672779" snippet_file_name="blog_20150522_4_2588442" name="code" class="java">public class Mainactivity extends Activity { @Override protected void OnCreate (Bundle Savedinstancestate) { super.oncreate (savedinstancestate); Initialize the context information before using each component of the sdk, passing in ApplicationContext //note that the method is implemented before Setcontentview the method sdkinitializer.initialize (getapplicationcontext ()); Setcontentview (r.layout.activity_main); } }</pre></pre><br><p><p></p></p><p style="font-family:微软雅黑; padding:0px 15px; margin-top:6px; margin-bottom:6px; color:rgb(98,98,98); font-size:14px; line-height:20px"><p style="font-family:微软雅黑; padding:0px 15px; margin-top:6px; margin-bottom:6px; color:rgb(98,98,98); font-size:14px; line-height:20px"><span style="color:red"><strong>note:</strong></span> <span style="color:red">before each functional component of the SDK is used, you need to call</span></p></p><p style="font-family:微软雅黑; padding:0px 15px; margin-top:6px; margin-bottom:6px; color:rgb(98,98,98); font-size:14px; line-height:20px"><p style="font-family:微软雅黑; padding:0px 15px; margin-top:6px; margin-bottom:6px; color:rgb(98,98,98); font-size:14px; line-height:20px"><span style="color:red">Sdkinitializer.initialize (getapplicationcontext ()); So we recommend that the method be put in the application initialization method</span></p></p><span style="color:rgb(98,98,98); font-family:微软雅黑; font-size:14px; line-height:20px"><span style="color:rgb(98,98,98); font-family:微软雅黑; font-size:14px; line-height:20px">Fifth step, Create map activity, Manage map Life cycle;</span></span><p style="font-family:微软雅黑; padding:0px 15px; margin-top:6px; margin-bottom:6px; color:rgb(98,98,98); font-size:14px; line-height:20px"><p style="font-family:微软雅黑; padding:0px 15px; margin-top:6px; margin-bottom:6px; color:rgb(98,98,98); font-size:14px; line-height:20px"><span style="white-space:pre"><span style="white-space:pre"><span style="color:rgb(98,98,98); font-family:微软雅黑; font-size:14px; line-height:20px"><br></span></span></span></p></p><pre code_snippet_id="672779" snippet_file_name="blog_20150522_5_688186" name="code" class="java">public class Mainactivity extends Activity {mapview mmapview = null; @Override protected void onCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Initialize the context information before using each component of the sdk, passing in Applicationcontext//note that the method is implemented before Setcontentview the method sdkinitializer.initialize (getapplicationcontext ()); Setcontentview (r.layout.activity_main); Gets the map control reference Mmapview = (mapview) Findviewbyid (r.id.bmapview); } @Override protected void OnDestroy () {super.ondestroy (); Execute Mmapview.ondestroy () when activity executes ondestroy, implement map life cycle management Mmapview.ondestroy (); } @Override protected void Onresume () {super.onresume (); Executes Mmapview when the activity executes Onresume. Onresume () to achieve Map lifecycle management Mmapview.onresume (); } @Override protected void OnPause () {super.onpause (); Executes Mmapview when the activity executes Onpause. OnPause () for map life cycle management MMAPVIEw.onpause (); } }</pre><span style="color:rgb(98,98,98); font-family:微软雅黑; font-size:14px; line-height:20px"><span style="color:rgb(98,98,98); font-family:微软雅黑; font-size:14px; line-height:20px">after completing the above steps, run the program to display the following map in your app:</span></span><p><p></p></p><p style="font-family:微软雅黑; padding:0px 15px; margin-top:6px; margin-bottom:6px; color:rgb(98,98,98); font-size:14px; line-height:20px"><p style="font-family:微软雅黑; padding:0px 15px; margin-top:6px; margin-bottom:6px; color:rgb(98,98,98); font-size:14px; line-height:20px"><span style="white-space:pre"><span style="white-space:pre"><span style="color:rgb(98,98,98); font-family:微软雅黑; font-size:14px; line-height:20px"><br><br><br></span></span></span></p></p><p><p><span style="white-space:pre"><span style="white-space:pre"><strong><span style="font-size:18px"><span style="white-space:pre"></span>second, the basic map</span></strong></span></span></p></p><p><p><span style="white-space:pre"><span style="white-space:pre"><br></span></span></p></p><p><p><span style="white-space:pre"><span style="white-space:pre"><span style="white-space:pre"></span>(1), Map Type</span></span></p></p><p><p><span style="white-space:pre"><span style="white-space:pre"><span style="white-space:pre"></span></span></span></p></p><pre code_snippet_id="672779" snippet_file_name="blog_20150522_6_3376092" name="code" class="java"><pre code_snippet_id="672779" snippet_file_name="blog_20150522_6_3376092" name="code" class="java">Mmapview = (mapview) Findviewbyid (r.id.bmapview); Mbaidumap = Mmapview.getmap (); General map Mbaidumap.setmaptype (baidumap.map_type_normal); Satellite map Mbaidumap.setmaptype (baidumap.map_type_satellite);</pre></pre><span style="white-space:pre"><span style="white-space:pre"></span></span>(2), Real-time traffic map<p><p></p></p><p><p><span style="white-space:pre"><span style="white-space:pre"><span style="white-space:pre"></span></span></span></p></p><pre code_snippet_id="672779" snippet_file_name="blog_20150522_7_217298" name="code" class="java"><pre code_snippet_id="672779" snippet_file_name="blog_20150522_7_217298" name="code" class="java">Mmapview = (mapview) Findviewbyid (r.id.bmapview); Mbaidumap = Mmapview.getmap (); Turn on traffic map mbaidumap.settrafficenabled (true);</pre></pre><span style="white-space:pre"><span style="white-space:pre"></span></span>(3), Urban Heat Force diagram<p><p></p></p><p><p><span style="white-space:pre"><span style="white-space:pre"></span></span></p></p><pre code_snippet_id="672779" snippet_file_name="blog_20150522_8_6709840" name="code" class="java"><pre code_snippet_id="672779" snippet_file_name="blog_20150522_8_6709840" name="code" class="java">Mmapview = (mapview) Findviewbyid (r.id.bmapview); Mbaidumap = Mmapview.getmap (); Turn on traffic map mbaidumap.setbaiduheatmapenabled (true);</pre></pre><span style="white-space:pre"><span style="white-space:pre"></span></span>(4), logo Cover<p><p></p></p><p><p><span style="white-space:pre"><span style="white-space:pre"></span></span></p></p><pre code_snippet_id="672779" snippet_file_name="blog_20150522_9_6898333" name="code" class="java"><pre code_snippet_id="672779" snippet_file_name="blog_20150522_9_6898333" name="code" class="java">Define maker coordinate points latlng point = new latlng (39.963175, 116.400244); Build the marker icon bitmapdescriptor bitmap = bitmapdescriptorfactory . fromresource (r.drawable.icon_marka); Build markeroption to add marker overlayoptions option = new Markeroptions () to the map . position (point) . icon ( bitmap); Add marker on the map and show Mbaidumap.addoverlay (option);</pre></pre><br><br><span style="white-space:pre"><span style="white-space:pre"></span></span>(5), Text Overlay<p><p></p></p><p><p><span style="white-space:pre"><span style="white-space:pre"></span></span></p></p><pre code_snippet_id="672779" snippet_file_name="blog_20150522_10_882621" name="code" class="java"><pre code_snippet_id="672779" snippet_file_name="blog_20150522_10_882621" name="code" class="java">Defines the coordinate point displayed by the text latlng lltext = new LATLNG (39.86923, 116.397428); Constructs the text option object to add text to the map overlayoptions textoption = new textoptions () . bgColor (0xaaffff00) . fontSize (in) . FontColor (0xffff00ff). Text ("baidu map Sdk") . rotate ( -30) . position (lltext); Add the text object on the map and display Mbaidumap.addoverlay (textoption);</pre></pre><br><span style="white-space:pre"><span style="white-space:pre"></span></span>(6), pop-up window covering<p><p></p></p><p><p><span style="white-space:pre"><span style="white-space:pre"></span></span></p></p><pre code_snippet_id="672779" snippet_file_name="blog_20150522_11_9393049" name="code" class="java"><pre code_snippet_id="672779" snippet_file_name="blog_20150522_11_9393049" name="code" class="java">Create a View button button for Infowindow display = New button (getapplicationcontext ()); Button.setbackgroundresource (r.drawable.popup); Defines the coordinate point used to display the Infowindow latlng pt = new LATLNG (39.86923, 116.397428); Create infowindow, incoming view, geographic coordinates, y-axis offset Infowindow Minfowindow = new Infowindow (button, pt, -47); Display Infowindow Mbaidumap.showinfowindow (minfowindow);</pre></pre><br><span style="white-space:pre"><span style="white-space:pre"></span></span>(7), Search Results covering<p><p></p></p><p><p><span style="white-space:pre"></span></p></p><p style="font-family:微软雅黑; padding:0px 15px; margin-top:6px; margin-bottom:6px; color:rgb(98,98,98); font-size:14px; line-height:20px"><p style="font-family:微软雅黑; padding:0px 15px; margin-top:6px; margin-bottom:6px; color:rgb(98,98,98); font-size:14px; line-height:20px">For the retrieval function module (poi search, line planning, etc.), The Map SDK also provides the corresponding covering to quickly display the result Information. These methods are open source, developers can according to their own actual request to do personalized Customization.</p></p><p style="font-family:微软雅黑; padding:0px 15px; margin-top:6px; margin-bottom:6px; color:rgb(98,98,98); font-size:14px; line-height:20px"><p style="font-family:微软雅黑; padding:0px 15px; margin-top:6px; margin-bottom:6px; color:rgb(98,98,98); font-size:14px; line-height:20px">Use the results overlay to show poi search results in the following ways:</p></p><p style="font-family:微软雅黑; padding:0px 15px; margin-top:6px; margin-bottom:6px; color:rgb(98,98,98); font-size:14px; line-height:20px"><p style="font-family:微软雅黑; padding:0px 15px; margin-top:6px; margin-bottom:6px; color:rgb(98,98,98); font-size:14px; line-height:20px">The first step is to construct a custom Poioverlay class;</p></p><p style="font-family:微软雅黑; padding:0px 15px; margin-top:6px; margin-bottom:6px; color:rgb(98,98,98); font-size:14px; line-height:20px"><p style="font-family:微软雅黑; padding:0px 15px; margin-top:6px; margin-bottom:6px; color:rgb(98,98,98); font-size:14px; line-height:20px"></p></p><pre code_snippet_id="672779" snippet_file_name="blog_20150522_12_9822305" name="code" class="java"><pre code_snippet_id="672779" snippet_file_name="blog_20150522_12_9822305" name="code" class="java">Private class Mypoioverlay extends Poioverlay {public mypoioverlay (baidumap baidumap) { Super (baidumap); } @Override Public boolean onpoiclick (int Index) { super.onpoiclick (index); return true; } }</pre></pre><br><span style="color:rgb(98,98,98); font-family:微软雅黑; font-size:14px; line-height:20px">the <span style="color:rgb(98,98,98); font-family:微软雅黑; font-size:14px; line-height:20px">second step is to add a custom poioverlay to the POI retrieval callback interface;</span></span><br><p><p></p></p><p style="font-family:微软雅黑; padding:0px 15px; margin-top:6px; margin-bottom:6px; color:rgb(98,98,98); font-size:14px; line-height:20px"><p style="font-family:微软雅黑; padding:0px 15px; margin-top:6px; margin-bottom:6px; color:rgb(98,98,98); font-size:14px; line-height:20px"><span style="color:rgb(98,98,98); font-family:微软雅黑; font-size:14px; line-height:20px"></span></p></p><pre code_snippet_id="672779" snippet_file_name="blog_20150522_13_1090595" name="code" class="java"><pre code_snippet_id="672779" snippet_file_name="blog_20150522_13_1090595" name="code" class="java">public void Ongetpoiresult (poiresult Result) { if (result = = NULL | | result.error = = SearchResult.ERRORNO.RESULT_NOT_ FOUND) { return; } if (result.error = = SearchResult.ERRORNO.NO_ERROR) { mbaidumap.clear (); Create Poioverlay Poioverlay overlay = new Mypoioverlay (mbaidumap); Set overlay to handle callout Click event mbaidumap.setonmarkerclicklistener (overlay); Set Poioverlay data overlay.setdata (result); Add Poioverlay to map overlay.addtomap (); Overlay.zoomtospan (); return; } }</pre></pre><span style="color:rgb(98,98,98); font-family:微软雅黑; font-size:14px; line-height:20px">The results of the <span style="color:rgb(98,98,98); font-family:微软雅黑; font-size:14px; line-height:20px">operation are as Follows:</span></span><br><br><p><p></p></p><span style="white-space:pre"><span style="white-space:pre"><span style="white-space:pre"><br></span></span></span><p><p><span style="white-space:pre"><span style="white-space:pre"><span style="white-space:pre">share</span> to this end ~ If in doubt can leave a message, together Exchange ~ ~</span></span></p></p><p><p>Android-baidu Map Call (base Version)</p></p></span>
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