1

I want to share a coordinate from my app, I want to able my users to choose another gps app and launch them . i've this code but it only opens google map , I want to make my user able to choose an app

    Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
    Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345"));
startActivity(intent);

how can I do so ?

Navid Abutorab
  • 1,667
  • 7
  • 31
  • 58
  • If you can share it directly as comma separated string as text/plain and add intent that can handle it. It should work. – karan Jan 05 '19 at 13:35
  • 1
    Possible duplicate of [How to open standard Google Map application from my application?](https://stackoverflow.com/questions/6205827/how-to-open-standard-google-map-application-from-my-application) – Alexander Hoffmann Jan 05 '19 at 13:40

1 Answers1

0

If you want a chooser, which will offer to the user all the apps with maps in his device, try this solution:

  1. To your manifest add data android:scheme="geo", but divide intent-filters to 2 parts as you can see below:

code:

<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.VIEW" />
                    <data android:scheme="geo" />
     </intent-filter>

After this you can work with geo links.

  1. Create an intent on button click or anywhere:

     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));```
    

This should offer to the user all his map apps (Google, Waze, Locus etc.) which he has installed. Also it shows that coordinates on the map, Waze also calculates the route automatically there.

You should also take care of the situoation if the user doesn't have any map app, create some exception.

Darksymphony
  • 2,155
  • 30
  • 54