Designing a Multi‑Map Architecture for Mobile Apps: Best Practices and Pitfalls
This article explains how to choose, layer, and encapsulate multiple map SDKs for iOS and Android, covering map selection, interface design, singleton vs. multiple instances, provided APIs, advantages, drawbacks, and practical implementation details with illustrative screenshots.
1. Map Introduction
1.1 Apps Using Maps
Baidu Map – navigation and nearby search.
Little Pig Bus – custom shuttle service.
Shenzhou Car Rental – car booking.
KuMiKe Real‑time Bus – bus line queries.
Waze Social Navigation – real‑time traffic reports; acquired by Google for $966 million.
Core map functions include user location display, positioning, data services, travel services, trajectory tracking, and navigation.
Major mainstream maps: Google, Baidu, Amap (Gaode), Sogou.
Due to domestic restrictions, Google is unavailable in China; developers typically choose Baidu or Amap domestically, while using Google abroad.
2. Multi‑Map Layered Structure Design
3. Design Specification
Map selection : Use Baidu Map for domestic projects and Google for overseas projects; import both via pod if needed.
Map interface layer :
Select map at compile time using macros (different builds for domestic and overseas).
Singleton vs. multiple instances: a singleton can reduce CPU, memory, and network usage but may cause a 1‑3 second UI freeze on first load; avoid loading the map on the home page if possible.
Provided APIs :
Obtain map view and configure properties.
Basic map operations.
Create and clear markers.
Draw lines and shapes.
Map controls: reset, zoom in/out, compass.
Interaction handling: click, point selection.
Utility methods: screenshot, distance calculation, coordinate conversion.
Location service management and address parsing .
4. Advantages
Lower learning curve for map users.
Unified modifications: changes in the underlying layer propagate automatically.
Encapsulation avoids redundant code across pages.
Reduces complexity caused by supporting multiple map SDKs.
Shield business logic from map‑specific changes.
5. Disadvantages
Including two map SDKs increases the binary size (approximately 2 MB for Google on iOS).
Singleton map instances may retain markers across pages; clear them in viewWillDisappear.
6. Extensions
Prefer map provider APIs (e.g., reverse geocoding) over native SDK calls for better reliability.
Recent Baidu Map versions support marker clustering.
Large trajectory datasets can cause lag; a 5‑second interval is generally acceptable for up to four hours of data.
iOS coordinates require conversion to the GCJ‑02 (Mars) system to avoid hundreds of meters of offset.
7. What We Can Do with Maps
Marker usage – see screenshots.
Trajectory drawing and playback (including fast‑forward and rewind).
Multi‑info markers, user location sharing, map controls (reset, zoom), and simple map view configuration.
8. Current Situation
The existing codebase embeds map logic directly in business layers, leading to scattered, redundant code, difficult unified fixes, steep learning curves for new developers, extensive changes when switching maps, and lack of support for multiple maps. Centralized location management also offers power‑saving benefits.
9. Optimization Points
Encapsulate map functionality behind a unified API to hide SDK differences.
Provide separate implementations for domestic and overseas maps.
Centralize location services so other modules can retrieve coordinates via a single interface.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITFLY8 Architecture Home
ITFLY8 Architecture Home - focused on architecture knowledge sharing and exchange, covering project management and product design. Includes large-scale distributed website architecture (high performance, high availability, caching, message queues...), design patterns, architecture patterns, big data, project management (SCRUM, PMP, Prince2), product design, and more.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
