从谷歌地图向带有地理信息的安卓应用程序发送意向



我想将Intent从谷歌地图发送到我正在开发的Android应用程序,其中包括地理信息(纬度、经度等(。

我知道这需要设置一个意向过滤器,但到目前为止,我唯一能做的就是纯文本过滤器:

<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
</intent-filter>

然而,这只给了我这样的文本描述:

899 Green St, San Francisco, CA 94133, https://goo.gl/maps/R4A82MNvUpA2

我已经尝试了以下内容,但没有奏效(意图甚至没有在谷歌地图中注册(:

<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="geo" />
</intent-filter>

有人知道怎么做吗?我使用的是安卓9(Pie(。

我遇到了类似的问题,我找到了一种方法。

使用地理编码获取位置数据:

https://maps.googleapis.com/maps/api/geocode/json?address=899+Green+St,+San+Francisco,+CA+94133&key=您的密钥

你会用一堆其他数据来计算lat和lng:

{
"results": [
{
"address_components": [
{
"long_name": "899",
"short_name": "899",
"types": [
"street_number"
]
},
{
"long_name": "Green Street",
"short_name": "Green St",
"types": [
"route"
]
},
{
"long_name": "Russian Hill",
"short_name": "Russian Hill",
"types": [
"neighborhood",
"political"
]
},
{
"long_name": "San Francisco",
"short_name": "SF",
"types": [
"locality",
"political"
]
},
{
"long_name": "San Francisco County",
"short_name": "San Francisco County",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "California",
"short_name": "CA",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "United States",
"short_name": "US",
"types": [
"country",
"political"
]
},
{
"long_name": "94133",
"short_name": "94133",
"types": [
"postal_code"
]
}
],
"formatted_address": "899 Green St, San Francisco, CA 94133, USA",
"geometry": {
"bounds": {
"northeast": {
"lat": 37.7989435,
"lng": -122.4128121
},
"southwest": {
"lat": 37.7982939,
"lng": -122.4138552
}
},
"location": {
"lat": 37.7988047,
"lng": -122.4131897
},
"location_type": "ROOFTOP",
"viewport": {
"northeast": {
"lat": 37.79996768029149,
"lng": -122.4119846697085
},
"southwest": {
"lat": 37.7972697197085,
"lng": -122.4146826302915
}
}
},
"place_id": "ChIJrd0tGO6AhYARxCp3djZ6Ka0",
"types": [
"premise"
]
}
],
"status": "OK"
}

相关内容

最新更新