Using Baidu map Android SDK to highly imitate wechat sending location function and problems encountered

I have been in contact with Baidu map development platform for half a month. In these two days, I tried to imitate the function of sending location to friends through wechat, and my ability to operate Baidu map has reached a new level

I have encountered some difficulties in implementing this function, which may also be the difficulties that others will encounter, which are listed here

1. In the wechat sending function, no matter how users drag and drop the map, there is always a cover fixed in the center of MapView. How to realize it?

In fact, this is easy to implement. As long as an ImageView is covered in the center of the MapView in the layout file of the MapView, it can be fixed in the center of the MapView no matter how the user drags the map

2. How to obtain the geographic coordinates of the center of MapView, that is, the coordinates at the screen coverage?

To obtain the geographic coordinates of the center of MapView, first obtain the physical coordinates of the covering on the screen. Here, we have to distinguish between geographic coordinates (longitude and latitude) and physical coordinates (XY axis);

Can pass

To obtain the physical coordinates. The physical coordinates are unchanged, while the geographic coordinates corresponding to the physical coordinates change with the user dragging the map. Therefore, when we need geographic coordinates, we can use the

obtain.

3. How to obtain all POI information around the geographic coordinates (that is, the information of surrounding buildings), not just a certain type of interest?

In order to realize this function, it really took me a lot of effort, because I always thought it was realized by POI peripheral search. Someone suggested that I can realize different keyword search through circular axis search, but it is really difficult to achieve the same effect as wechat. By viewing the API, you can find that you can solve this problem through anti geocoding. As for what anti geocoding is, you can go to the official website of Baidu maps. By calling it, you can return a list of building information near the geographical coordinates

4. When users drag and drop a map, how to update the list to the surrounding information of the current central geographic location?

In fact, this difficulty is not difficult to implement, but rewrite mbaidumap. Setonmaptouchlistener (touchlistener); Touch event, in the callback function of the touch listener

Convert the physical coordinates in the center of MapView into corresponding geographical coordinates, and then obtain the surrounding information through anti geocoding. The reason is the same as that in question 3

5. When clicking an item in listview, how to display the geographical location of the item in MapView, that is, the center of the screen?

Very simple, get the location information of the item, including longitude and latitude, through the listview adapter, and then jump to the center of the screen with animation.

I think the above five problems are the key to realize this function. The following is the effect diagram

Above is a MapView, the cover is fixed in the center, and the white square in the lower left corner of the map is the button to return to the positioning point. Because no good-looking picture is found, it is left blank

Below is a listview that displays some location information around the location indicated by the map

Post the core code to realize this function

Activity class

Custom listview adapter

summary

The above is what Xiaobian introduced to you. We hope to help you by using the high imitation wechat sending location function of Baidu map Android SDK. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>