Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending an Intent from Google Maps to an Android app with geo information

I'd like to send Intent from Google Maps to the Android app I'm developing, that would include geo information (latitude, longitude, etc).

I know it requires setting up an intent filter, however the only one I got working so far is the plain/text one:

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

This however only gives me textual description looking like this:

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

I've experimented with the below, however that didn't work (the intent wasn't even registered in Google Maps):

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

Does anyone know how to do this? I'm using Android 9 (Pie).

like image 318
daniel Avatar asked Nov 09 '18 22:11

daniel


People also ask

Is Google Maps API free for Android?

Note that the Maps Embed API, Maps SDK for Android, and Maps SDK for iOS currently have no usage limits and are at no charge (usage of the API or SDKs is not applied against your $200 monthly credit).

Does Google Maps provide an API?

What is the Google Maps Platform? The Google Maps Platform is a set of APIs and SDKs that allows developers to embed Google Maps into mobile apps and web pages, or to retrieve data from Google Maps.


1 Answers

I was having a similar problem and I found a way.

use geocoding to get location data:

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

you will the lat and lng with a bunch of other data:

{
    "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"
}
like image 143
Pemba Tamang Avatar answered Oct 31 '22 11:10

Pemba Tamang