Fragment supported by Baidu map (note)

Source: Internet
Author: User
Original article: fragment supported by Baidu map (note) Opening part:
The old Baidu map usually inherits mapactivity, which is not conducive to code scalability. In addition, with the popularity of fragment, the old Baidu map is far from meeting everyone's needs, so the new version of Baidu map came out. It no longer needs to inherit mapactivity. developers can use them as they wish.

Note:
1. If you want to use the new Baidu map API, you need to apply for a new key (the old version of Baidu map corresponds to the old key, which is still available on Baidu official website ).
Click here to go to the website for applying for a new key (Baidu official website)

2. New key mechanism: each key is valid only for one application, that is, the application that matches the package name used in the key configuration process. Therefore, you must apply for multiple keys for multiple applications (including multiple Package Names) or configure one key multiple times.
Click here to go to the new key application process

3. The method public Boolean Init (mkgenerallistener listener) in the bmapmanager class starts from version 2.4.1. The key does not need to be passed in through this interface, but is placed in Mata-data of androidmanifest. XM.

4. download the latest Baidu map API from the official website. The demo can be used for reference.
Click here to go to the latest Baidu map API download URL


5. After the preparation is complete, you can officially start coding the latest Baidu map.
Click here to write the "Hello World" demo
Be sure to follow this process strictly,
(1) Add the required JAR file and so file (do not forget the. So file );
(2) Add one or fewer permissions;
(3) The most important thing is the key storage. When I run the code, I always prompt information about the authorization key error. I tried many ways to solve this problem, after that, I asked my colleagues to apply for a key for me. I don't know why. If you encounter such problems in future development, first check whether these processes are in place, and then ask other colleagues to apply for a new key, to apply for a new key, follow the process on the official website.

  1. <Meta-data Android: Name = "com. Baidu. lbsapi. api_key" Android: value = "Development Key">
  2. </Meta-data>
6. The most important thing is to join the service.

<Service

  1. Android: Name = "com. Baidu. Location. F"
  2. Android: enabled = "true"
  3. Android: Process = ": Remote"
  4. Android: Permission = "android. Permission. baidu_location_service">
  5. <Intent-filter>
  6. <Action Android: Name = "com. Baidu. Location. service_v2.6"> </Action>
  7. </Intent-filter>
  8. </Service>

7. Be sure:
Locationclient mlocclient = new locationclient (getapplicationcontext ());
If it is written in fragment, it should be written as mlocclient = new locationclient (getactivity (). getapplicationcontext ());
Otherwise, the oncancelocation function will not be executed. I have been entangled for a long time here. I hope you will not repeat the same mistakes.

Postscript:
As long as you strictly follow this process, the new version of Baidu map can be used (of course, it can be used in fragment). I have passed the operation and hope that developers can run smoothly.



Fragment supported by Baidu map (note)

Related Article

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.