Maps on Baidu map SDK- true sense

Maps on Baidu map SDK- true sense

In the blog post, and I told locate objects by instantiating LocationClient, after obtaining permission to apply for a series of calls start LocationClient object () method open position, and the positioning of return to listeners inside, became a band BDlocation object position information, and then we inside the listener through a series of methods, such as getLatitude () Gets the latitude, getLongitude () Gets longitude into a location information we can know.

However, only the text description of the geographical information is not the result we want, we are going to need to continue to improve, so that you can see in the map, and you can find their place.

First, we need to layout file inside the TextView control is removed, of course, you can also set the Layout: Visibility = "gone", then is to add a MapView control and note that the package name we write complete.

<com.baidu.mapapi.map.MapView
        android:id="@+id/bmapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clickable="true" />

Then we need to operate in the event inside. First, we need to instantiate a MapView object.

private MapView mapView;
****
mapView = (MapView) findViewById(R.id.bmapView);

Running at the time, we first see a map of Beijing on the phone, but can not find their place.
Write pictures described here

If anyone can see numerous white plaid, then you need to look at the application key when there is no erroneous information, I have encountered such a situation, re-fill the next SHA1, and package name, OK .

Next, we need to find your location on the map.

We need the MapView getMap () method to get BaiduMap the core management class.

 private BaiduMap baiduMap;
 baiduMap = mapView.getMap();
        //BaiduMap是地图的总控制器

LatLng here to use this class, by passing their latitude and longitude information to its constructor to instantiate it, followed by the object to obtain a MapStatueUpdate MapStatusUpdateFacotory of newLatLng () method, then the object as a parameter to MapStatueUpdate to BaiduMap management class animateMapStatus () method which, at this time we can see their location on a map of the area. But still can not see your location, a few days ago to write up according to Guo Lin teacher code, find understanding in Beijing to see the map after opening the software, carefully compared the code with the teacher, the teacher discovered by two animateMapStatus () method
Write pictures described here
feeling for the first time animateMapStatus () method of passing information to the latitude and longitude information is scaled cover. So, after playing up what we see is the default map in Beijing.

Own region is displayed, and the next is how to find their natural position, the same Baidu map also provides MyLocationData this class to help us.

First we need MyLocationData.Builder () to instantiate MyLocationData object, and then add a series of data for this object.

MyLocationData data=new MyLocationData.Builder()//
        .accuracy(location.getRadius())//
        .latitude(location.getLatitude())//
        .longitude(location.getLongitude()).build();
        baiduMap.setMyLocationData(data);
        //让自己显示在地图上

Then we run, look at the effect in the end is how the
Write pictures described here
Qiqihar City is also a good place, we have the opportunity to take a look at Zhalong wetland.
Here we have the content of this blog is finished, in fact, I was a novice, if there are children's shoes interested in Android development, we can learn together.
Write pictures described here

Published 37 original articles · won praise 10 · views 10000 +

Guess you like

Origin blog.csdn.net/OneLinee/article/details/78289163