Foreword:
When going out, taking the bus or subway is inevitable. Not knowing the transit route is definitely not an option. Using the official app has many drawbacks, and checking online via a mobile browser is both slow and troublesome... To solve these problems, let's create a simplified version of a travel assistant. Mom will never have to worry about me getting lost again! _\^o^/_
I. Functional Requirements Analysis
Basic Functions:
- Able to query transit routes based on starting and ending stations and display multiple options.
- Able to query stations along a bus route by route number (to prevent missing your stop...).
Extended Functions:
- Use GPS to get the starting station (name of the station closest to the current location) [Later abandoned: consumes battery and data...].
- Display map [Later abandoned: maps don't seem very useful for users (unless they like walking), at least for me, the map isn't very useful].
II. Feasibility Analysis
1. The API provided by the Baidu Maps Open Platform can implement transit route queries.
2. 3. 4. Same as above. Conclusion: All required functions can definitely be implemented.
III. Development Prerequisites
- Need a Baidu Maps developer account.
- Need a key (the new version of the map key is uniquely bound to the App).
- Need the jar package provided officially.
Search for “Baidu Maps development”, and the three things above can be sorted out in minutes (I have to praise the extremely low barrier to entry here; developer accounts for Tencent, Sina Weibo, etc., are hard to verify, and some even require uploading copies of ID cards...).
IV. Studying API Documentation and Demos
To be honest, the API documentation isn't great; the function descriptions are only one sentence long. I recommend looking directly at the Demo, which comes with plenty of comments and is easy to understand.
V. Start Coding (The source code provided below has been tested and works, and includes very detailed comments)
Source code can be found at [Source Code Download]
P.S. All the source code is above. If you have any questions, please leave a comment below.
VI. Displaying the Map
[This was the first thing I implemented (I was a bit excited during my first map development and wanted to see what it looked like...). It wasn't planned in the requirements, and although I later abandoned it, the source code below is still tested and correct.]
Source code can be found at [Source Code Download]
VII. Offline Maps
Offline maps have many benefits. However, if you are developing an app to be promoted to many users, I suggest either adding an offline map package download function (there is a routine in the Demo, it's easy) or considering copying the offline maps from the APK resource files to the user's SD card when the App runs for the first time (it can be implemented in theory). Of course, this limits the map's scope, but it's an option for developing apps with clear regional restrictions (e.g., Xi'an Travel Assistant).
Offline maps are used like this:
- Copy the entire folder downloaded from the official website to the specified path on the phone's SDCARD (see the ReadMe.txt in the zip file for details on where to put it).
- The offline map package needs to be initialized with a scan in the program (it essentially parses the map package, turning a large file into several small files; therefore, the map package is unusable without parsing).
- It seems the method for displaying maps will automatically decide (prioritizing offline maps if available).
VIII. Screenshots of Running Interface

No comments yet. Be the first to share your thoughts.