Skip to content

fix(navigation): load AMap JS SDK for Autocomplete search#304

Closed
conversun wants to merge 1 commit intoFrogAi:FrogPilotfrom
conversun:fix/amap-sdk-loading
Closed

fix(navigation): load AMap JS SDK for Autocomplete search#304
conversun wants to merge 1 commit intoFrogAi:FrogPilotfrom
conversun:fix/amap-sdk-loading

Conversation

@conversun
Copy link

Summary

The AMap (高德地图) JavaScript SDK is referenced in the navigation search code but was never loaded, causing ReferenceError: AMap is not defined when users toggle to the AMap search provider.

Bug

navigation_destination.js calls new AMap.Autocomplete() in two places (handleSearchKey and searchInput) but the AMap JS SDK is never loaded — neither statically in index.html nor dynamically in JavaScript. This means AMap-based destination search is completely broken.

Fix

index.html (+1 line):

  • Added <script src="https://webapi.amap.com/loader.js"></script> to load the AMap JSAPI Loader

navigation_destination.js (+42 lines):

  • Added ensureAMapLoaded() lazy-load singleton function that:
    • Configures window._AMapSecurityConfig with the user's security key (AMapKey2)
    • Calls AMapLoader.load() with the user's API key (AMapKey1), version 2.0, and AMap.Autocomplete plugin
    • Caches the load promise to avoid redundant SDK loads
    • Handles errors with user-facing showSnackbar() feedback
  • Updated both AMap search paths (handleSearchKey and searchInput) to await ensureAMapLoaded() before creating Autocomplete instances

Testing

  • Requires valid AMap API keys (Key Update interface.py #1 and Key Space pilot #2) configured in device settings
  • Toggle search provider to "Amap" and search for a destination
  • Verify autocomplete suggestions appear
  • Verify error message appears if keys are invalid or network is unavailable

@github-actions
Copy link

Please submit your pull request to the "MAKE-PRS-HERE" branch.

@github-actions github-actions bot closed this Feb 28, 2026
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 23abff043e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

securityJsCode: state.amap2Key
};

amapLoadPromise = AMapLoader.load({

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle missing AMapLoader before calling load

If https://webapi.amap.com/loader.js fails to load (e.g., offline device, CDN blocked, or strict CSP), AMapLoader is undefined here and this statement throws a ReferenceError before the promise .catch() can run. In that case both AMap search paths fail with an uncaught error and users never see the intended snackbar fallback, so the new error handling does not actually cover this common failure mode.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant