“This is the 27th day of my participation in the August Gwen Challenge.

The last tweet briefly introduced the interaction with the map, such as moving, zooming, clicking, screenshots, etc., are very common business. Let’s learn how to dot, mark information, draw lines and surfaces on a map.

Welcome friends to search “Andy Hui” on wechat to pay attention to a wave!

Write some thoughts of the programmer, hope it will help you.

Public link: Baidu Map development – drawing dot line prompt box 07 (QQ.com)

Mark points, draw lines, surfaces, and add prompt information

About the function of drawing points on Baidu map, in fact, has a great role, for example, we query the hotel in the map, meet the requirements can be displayed in the form of marked points, users can see the specific location at a glance. At the same time, if you can add the corresponding pop-up information of the hotel on the marked point, then the user can see it more clearly.

Dot notation

Dot markers are used to mark any location on a map, such as user location, vehicle location, store location, anything with location attributes.

Add dot mark

/ / get the current position LatLng point = new LatLng (currentLocation. GetLatitude (), currentLocation. GetLongitude ()); / / build BitmapDescriptor Marker icon bitmap. = BitmapDescriptorFactory fromResource (R.d rawable. The flag); // Add Marker to map and display mbaidumap.addoverlay (new MarkerOptions().position(point).icon(bitmap));Copy the code

After clicking Add Tag, you can add tag information at the current location.

As for Marker, Baidu officially gives quite high permission for customization. ICONS, animation types, transparency, whether they can be dragged and title can all be adjusted and customized operations can be carried out according to requirements. The tutorial also says you can add click and drag events to tag points.

Draw the line

According to the corresponding tutorial writing method, can achieve the drawing broken line, dashed line, segmented color drawing line, segmented texture drawing line, through the whole function can draw a variety of planning routes or object track.

LatLng p1 = new LatLng(39.077218, 117.072102); LatLng P2 = New LatLng(39.007423, 117.110989); LatLng P3 = new LatLng(39.077218, 117.172345); List<LatLng> points = new ArrayList<LatLng>(); points.add(p1); points.add(p2); points.add(p3); OverlayOptions mOverlayOptions = new PolylineOptions().width(10).color(0xAAFF0000).points(points); Overlay mPolyline = Overlay mpolymap.addoverlay (mOverlayOptions); // Overlay mPolyline = Overlay mpolymap.addoverlay (mOverlayOptions);Copy the code

Color, width, Points coordinate list, Colorsvalues segment color list, extralNFO extralNFO, etc.

You can also add a line click event, which can be used when you need to click on a drawn route.

For drawing this can also draw arc, draw polygons, draw circles, etc. You can refer to Baidu map tutorial on their own can be realized as needed.

Next, add text and a message window, which is essentially a popover message.

Word overlay

It’s just a point on the map, and it’s written

LatLng ll = new LatLng (39.077218, 117.072102); OverlayOptions mTextOptions=new TextOptions().text(" aaffff00 ").bgcolor (0xAAFFFF00) // background color.fontsize (24) // fontSize .fontcolor (0xFFFF00FF) // Text color.rotate (-30) // position(ll); Overlay mText=mBaiduMap.addOverlay(mTextOptions);Copy the code

Add Information box

In this tutorial, there are two ways to display an info-box, one is to use a View to construct an InfoWindow, and the other is to use a BitmpDescriptor to construct an InfoWindow. So let’s just implement the first one here.

Button Button =new Button(getApplicationContext()); button.setBackgroundResource(R.drawable.flag); Button.settext (" Button.settext "); LatLng P1 = New LatLng(39.007423, 117.110989); mBaiduMap.showInfoWindow(new InfoWindow(button,p1,-100));Copy the code

Here I just temporarily find a picture to pop up the bottom of the box, the function of the first to achieve again. Everyone in the process of using to do a little bit better picture, so that the overall beauty of the software will be improved.

Basically, the interaction with the map is introduced here. At present, it is just a simple talk about some commonly used functions. As for some details, I still need to see the official document of Baidu, although I am not very cold to that document.

A word of warning to everyone, see the DEMO, it is much better than the official documentation tutorial.

Small remarks

Life is short, I don’t want to go after what I can’t see, I just want to catch what I can see.

Original is not easy, give a attention.

I am Hui, thank you for reading, if it is helpful to you, please like, forwarding thank you.