You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter如何接收位置Intent实现跨APP坐标跳转?

处理Google Maps坐标分享的实现方案

你可以基于已用的receive_sharing_intent插件扩展实现,不需要换全新插件,核心是处理Google Maps分享的geo类型数据,步骤如下:

  • 配置Intent过滤
    在Android项目的AndroidManifest.xml中,给目标Activity添加能接收geo协议和文本分享的Intent过滤器,确保你的应用出现在Google Maps的分享列表里:

    <!-- 接收文本类分享(含geo链接或经纬度文本) -->
    <intent-filter>
        <action android:name="android.intent.action.SEND" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="text/plain" />
    </intent-filter>
    <!-- 直接响应geo协议链接的打开请求 -->
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="geo" />
    </intent-filter>
    

    iOS端则需要在Info.plist中添加geo到LSApplicationQueriesSchemes数组,并配置UIActivityTypes支持分享接收。

  • 解析分享数据
    用receive_sharing_intent监听分享回调,拿到数据后做针对性解析:

    • 如果是geo:开头的字符串,用正则提取经纬度,比如匹配geo:([-+]?\d+\.\d+),([-+]?\d+\.\d+),分组1是纬度,分组2是经度;
    • 如果是普通文本,先尝试匹配\d+\.\d+,\s?\d+\.\d+格式的经纬度,若匹配失败则视为地址文本,调用地理编码接口转成经纬度。
  • 自有地图加载坐标
    解析出经纬度后,直接传入你的自有地图组件,调用地图的定位方法将镜头移动到该坐标即可。

如果不想依赖receive_sharing_intent,也可以直接在原生层处理Intent回调,但基于现有插件扩展更节省开发成本。

内容的提问来源于stack exchange,提问作者bky

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 02:55:30