Baidu Map API Use Series 3-Basic map 1

Source: Internet
Author: User

Baidu Basic Map using 1

About Baidu Map application developer Key can refer to the previous blog

Baidu Map API Use Series 1-ready to work

For the construction of the project can refer to the previous blog

Baidu Map API Usage Series 2-Show Map

This blog introduces basic maps using the types of maps inside, displaying real-time traffic maps, and displaying a marker on the map.

Note here that the operation of the map does not have to show the map of the control directly to complete, Baidu added a property for him Baidumap can interpret this attribute as a map manager

We can get this property by the corresponding Get method

Baidumapbaidumapview. Getmap ();
Map type

Baidu Maps provides two types of map resources (normal vector maps and satellite maps)

Baidumap .   normal vector map
Baidumap .   Satellite map
Baidumap . Setmaptype (map_type);
/**  set the type of map to display  Map Type */
private voidSetdisplaymaptype (intCurrentmaptype) { Switch(currentmaptype) {Case    map_normal :         // Show map types are divided into two categories 1. General vector maps 2. Satellite mapBaidumap. Setmaptype (Baidumap.Map_type_normal);  Break; Case    map_satellite :        Baidumap. Setmaptype (Baidumap.Map_type_satellite);  Break; default:        Baidumap. Setmaptype (Baidumap.Map_type_normal);  Break;}

Show real-time traffic maps

Baidu has now supported traffic maps for multiple cities

Baidumap. settrafficenabled (Boolean);
 /** * Set display implementation traffic map * @param isChecked  display true show false do not show */private voidsetdisplaytraffic (BooleanisChecked) {    if(isChecked) { // show real-time traffic map Baidumap. settrafficenabled (true); }Else{        Baidumap. settrafficenabled (false); }}
Show a marker on the map
 /** * display labels on the map by latitude * @param longitude  Longitude * @param latitude /c8> Latitude * /private voidSETLATLNG (DoubleLongitude,Doublelatitude) {     // build the coordinates of the callout through latitude/longitude //This place needs to be aware that when instantiating a latlng class, it is latitude longitude when passing parameters.latlng point =Newlatlng (latitude, longitude); Bitmap Bitmap = bitmapfactory.Decoderesource(Getresources (), r.drawable.Ic_launcher);  // building display icons for labels with bitmap bitmapdescriptor bitmapdescriptor = bitmapdescriptorfactory. Frombitmap    (bitmap);  // Create a overlay //Set the coordinates of the callout position//Set the icon for the label icons//Set the title of the label title//Set the label to drag DRA Ggable true can be dragged and false can not drag long press function can listen to drag eventsoverlayoptions options =Newmarkeroptions (). Position (point). Icon (bitmapdescriptor). Title ( " Hao King building" ). Draggable (true); Baidumap. Setonmarkerdraglistener ( This);  // add overlay with map above //This method has a return value of OverlayMarker= (Marker)Baidumap. Addoverlay (options);  // Show Default overlay location Displaymarker ( " default" , Marker);}

remove removes from the map.   
The following is the source code of the entire program click to open the link

Baidu Map API Use Series 3-Basic map 1

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.