Nearby Customers Is Not Just Dropping Pins: Three-State Addresses, Single-Shot Location, and CRS Boundaries in GoodCRM
Field-sales discovery on Tab 5 broke in ways a map SDK won't fix: half of B2B addresses are plain text, mainland China coordinates mix GCJ-02 and WGS-84, and editing street text leaves stale pins attached. Wave 4 (b8bd31a) locked down explicit address states, single-shot location, and zero guessed coordinate conversions.
GoodCRM (1.0 live on the US App Store id6837223780; HarmonyOS in preparation) includes a “Nearby” tab for field sales to scan clients within 1 km, 3 km, or 5 km, pick a destination, and start navigation or schedule a visit.
During the code audit (TAB_AUDIT_AND_REMEDIATION.md, T5-P0-01 through T5-P2-01), the implementation gaps were glaring: Apple’s location check discarded the coordinates it fetched; HarmonyOS had no map widget at all and hardcoded Taipei 101 as its center; unconfirmed coordinates leaked into external navigation URLs; and editing an address string left the old pin silently attached.
Commit b8bd31a on November 14 (Wave 4) rebuilt Tab 5, single-shot location, address states, and navigation confirmation across both codebases.
Addresses Are Not a Binary “Has Pin / No Pin” Flag
Real B2B customer records rarely start with clean geocoded coordinates. Most begin as text pasted from WeChat or contracts, or carry pins dropped months ago before a client moved offices. Mixing unverified text and stale pins into one map query either hides half your accounts or sends you to the wrong building.
AddressViews.swift and Nearby4View.ets partition results into explicit groups alongside missing primary addresses:
- Confirmed points (
confirmed): Only coordinates matching the currentaddress_content_revision_refwithstatus == "confirmed"enter distance sorting, radius filtering (1 km/3 km/5 km/全部, converted to meters in Apple’s backend), and map marker clustering. - Text-only or unconfirmed (
unlocated): Plain-text, unconfirmed, orstaleaddresses stay visible in a dedicated section with a direct button to pin them rather than disappearing from Tab 5. - Unknown coordinate reference (
unknown_crs): Points taggedUNKNOWNare isolated from distance math and map overlays with a prompt to re-pin.
Wave 4 also fixed two state traps around edits and confirmations. On Apple (T5-P0-02), AddressEditorForm4 previously allowed status = .confirmed with confirmedAt = nil, which failed HarmonyOS’s strict invariant (status !== 'confirmed' || confirmed_at !== null, ADDRESS_INVALID_POINT); Apple now stamps ActionDates4.instant(Date()) when saving a confirmed pin with an empty timestamp. On HarmonyOS (T5-P1-03), setAddressText4 in Address4Forms.ts automatically clears point_enabled and point_dirty when the formatted text changes from its baseline so users don’t get stuck on ADDRESS_CONTENT_POINT_CONFLICT, while Apple gives an explicit toggle (“将当前地图位置保留到修改后的地址”) in AddressEditorForm4.
Zero Background Tracking: Single-Shot Location Only
A personal sales CRM has no business tracking a salesperson’s movement in the background.
Both platforms enforce user-triggered, single-shot location via LocationCheckButton4. Tapping “使用我的当前定位” requests one fix, records source = .user_selected_current_location, provider (e.g. Apple CoreLocation), and horizontal accuracy in meters, and populates the search center or address draft for review. Panning the map never triggers location permissions; users explicitly tap “按当前地图区域搜索” (searchInVisibleRegion()) or search places via MKLocalSearch.
On HarmonyOS, NativeNearbyMap4.ets wires up @kit.MapKit’s MapComponent, with a pragmatic fallback: if the map controller does not initialize within 1200 ms or returns an error (such as environments without HMS map services), it switches seamlessly to an interactive 2D Canvas coordinate plot supporting pan, zoom, radius rings, and marker selection.
Explicit Coordinate Systems: Never Guess a Conversion
Mixing WGS84 and GCJ02 without tracking which datum a point belongs to shifts pins across streets by hundreds of meters. Guessing an uncalibrated conversion formula makes things worse by baking silent drift into saved data.
LocationHost4.ts and ContactActions4.swift enforce one rule: store WGS84, GCJ02, or UNKNOWN explicitly, and refuse any guessed conversion.
LocationHost4.tsrejects anyfixpayload carryingconverted_latitude,converted_longitude, orconverted_coordinate_systemwithLOCATION_CONVERSION_REFUSED.- Visit snapshots (
Primary Nextvisits) andnavigate_addressrequests export coordinates only whenpoint.status === 'confirmed'; unconfirmed orUNKNOWNpoints strip lat/lng tonulland fall back to text-only destination queries. - External map URLs respect the recorded datum (
ContactActions4.swift):baiduWebURLpassescoord_type=gcj02orwgs84explicitly, whilegoogleNativeURL/googleWebURLattach coordinates only forWGS84and fall back to text search otherwise. - Before launching an external map app, a confirmation sheet shows the full address text, coordinate datum label, and a one-tap copy button (
copyText). Launching navigation never marks a visit complete (LOCATION_NAVIGATION_DOES_NOT_COMPLETE).
Wave 4 (b8bd31a) passed 457/0 Apple host tests and 542/0 HarmonyOS host tests alongside simulator and HAP builds; physical tablet hardware remained not_run at this checkpoint.
Comments