dan*_*iel 6 android google-maps
我想将Intent从谷歌地图发送到我正在开发的Android应用程序,其中包括地理信息(纬度,经度等).
我知道它需要设置一个intent过滤器,但到目前为止我唯一能使用的是纯文本/文本过滤器:
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
然而,这只给我看起来像这样的文字描述:
899 Green St, San Francisco, CA 94133, https://goo.gl/maps/R4A82MNvUpA2
Run Code Online (Sandbox Code Playgroud)
我已经尝试了下面的内容,但这不起作用(意图甚至没有在Google地图中注册):
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="geo" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
有谁知道如何做到这一点?我正在使用Android 9(Pie).
我遇到了类似的问题,我找到了一种方法。
使用地理编码来获取位置数据:
您将得到 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"
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
398 次 |
| 最近记录: |