Home » Android » Using Baidu maps Android SDK

Using Baidu maps Android SDK

  • well, Baidu maps,

  • Baidu maps, there are all kinds of tall features on offer, I will not. These two smallpox time looked at, ready to make a tall on the app out. I found that I want to more.

  • then, just a function of location, and show my location on the map,..

  • OK, let's start with the implementation of these two functions,

    • first, go to the Baidu Developer Center to download the Baidu maps SDK lib package, and then put it in your own project's lib package,.

    • then, Ann according to the official website provided code, step by step down to copy, log inside can print out the current position,.

    • again, and then the MapView is also copied according to the official website code, you can display the map, but the default location is Tiananmen in Beijing. Obviously, this is not what we want the effect.

    • LatLng, latLng = new, LatLng (mLatitude, mLongitude);

      MapStatusUpdate statusUpdate = MapStatusUpdateFactory.newLatLng (latLng);

      MBaiduMap.animateMapStatus (statusUpdate); / / display the current location in the center of the map to

      MBaiduMap.setMyLocationEnabled (true); / / open to display the current location icon

      With the lines above, you can display the current position on the map. Pay particular attention to the setting of the last switch, you must set it, or else it doesn't work.

      * by the way, the Java's default observer pattern API is pretty good, as long as it's in the production data method of the Observable implementation class,

      setChanged ();

      NotifyObservers (obj);

      ClearChanged (
      ); call these 3 lines of code, and then the observer (onUpdate) in the method can obtain the latest production data in real time. Of course, the premise is that need to be added to the Observer class container. Also is called the observer Java enhanced apiaddObserver (observer); .

    • because I have such a demand, not only allows users to see the positioning information in the non map interface, and allows the user to see the location information in the map interface, so I will be the two interface as the observer, the listener will get the location information as observation to achieve such a demand for.

    • Baidu map SDK API call is not introduced, believe that the introduction of the website is better than me. In addition, if you want to use Baidu map SDK, see the official website API and no eggs for children's shoes, please see the the video on the very good however, because it is in the 14 years, there are some subtle differences in API or to achieve the effect of possible and you the same code can achieve the effect. For example, the current location of the map display, it must be according to what I said above 3 lines of code to do, follow the link tutorial may have no way to see the current position..

    • well, that's about it,.

  • according to convention, finally must ha ha ha's //TODO.