Google maps now offers a way to "share a place" with what appears to be a predefined list of sources. When users search for a place on Google Maps, whether it's a specific address, cross-street, or restaurant name, there's a new button called "share this place" that posts the location info to Google Buzz, Facebook, Twitter, or via e-mail or SMS. I would like to either have my application included in this list or determine how to obtain the lat/lon of that selected location. Does anyone have any ideas?
Asked
Active
Viewed 3,378 times
6
-
I came here to ask this exact same question. I'll post the answer if I find out how to do it. – HenryAdamsJr Sep 16 '10 at 16:55
1 Answers
8
I figured it out. Here's a sample manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.yourapp" android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".YourApp" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND"></action>
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="4" />
</manifest>
Simply add the SEND intent filter just as it is above to your activity. The "share this place" simply performs a "SEND" intent with the mime type of "text/plain". If you register an intent filter for that type, then your app will show up in the list. Mine did. =)
HenryAdamsJr
- 840
- 2
- 9
- 21
-
Thanks Henry! I will give this a try as soon as the alligators allow. – stanlick Sep 21 '10 at 14:38
-
Sweet, that worked great! Now then, how is it working? Does my app have to be running to show up in the map's "share this place?" I don't see the connection between the two. Also, do I need a broadcast receiver or some such to receive the call back when the user selects my app? – stanlick Sep 21 '10 at 23:33
-
The way I've shown you above tells Android that your app can receive a send intent of type "text/plain". Your app does not have to be running for it to be in the list because when you select it, Maps with actually launch the activity your intent filter is defined on. Then, you simply pull the text out of the context that's passed to the activity. – HenryAdamsJr Sep 27 '10 at 18:53
-
2Is there any documentation concerning what I might expect to get back in the Bundle extras? I have experimented with a few places and what I get back appears to be nearly random! bundle.get("android.intent.extra.TEXT") returns a String where the variable number of lines are separated by a /n char. Also, some of the lines start off with a number (1,2,3) and others do not. I thought the 1 might signify phone number, however, some phone numbers returned were not preceded by the 1! Fishing random data out of a Bundle is crazy! – stanlick Sep 28 '10 at 23:08
-
2I didn't find any documentation, and I doubt there is any. I just played around with it until I got what I needed. I just wanted to be able to pull out the GPS coordinates. Also, could you please accept my answer. =) – HenryAdamsJr Sep 29 '10 at 04:24
-
4
-
1I would also want to know how you got the GPS coordinates from it. Google Maps just sends a shortened URL of the place in form of `goo.gl/maps/XyZ` – ercan Jan 10 '14 at 08:56
-
@HenryAdamsJr Please tell me how to get the gps coordinates from it i really need it :( – Varrox Systems Jun 15 '20 at 22:54
-
This post is almost 10 years old. You'd be better off with a new question as I'm sure anything that worked 10 years ago is irrelevant now. – HenryAdamsJr Jun 22 '20 at 20:26
-