Get latitude and longitude from google maps' shared location in my own Android app

117 Views Asked by At

I'm trying to share a location from Google Maps to my own Android, I'm doing it with an Intent in my app and I successfully get the Intent in my app, but I'm getting something like this:

https://maps.app.goo.gl/SUeYVuEWd5u9Xn5B8

So, the problem is that I can't get latitude and longitude from this URL.

In my AndroidManifest I have and intent filter in the activity where I want to get the location

<activity
            android:name=".activities.MainActivity"
            android:exported="true"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="text/plain" />
            </intent-filter>
</activity>

Then, in my activity I receive the intent in this way

Intent intent = getIntent();
        String action = intent.getAction();
        String type = intent.getType();

        if(Intent.ACTION_SEND.equals(action) && type != null) {
            if("text/plain".equals(type)) {
                String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
                if(sharedText != null) {
                    //sharedText = https://maps.app.goo.gl/SUeYVuEWd5u9Xn5B8
                    Geocoder geocoder = new Geocoder(this);
                    List<Address> addressesList = geocoder.getFromLocationName(sharedText, 1);
                }
            }
        }

But the addressesList object has a size of 0 since I can't get the location from https://maps.app.goo.gl/SUeYVuEWd5u9Xn5B8

Whats is the best way to get latitude and longitude?

0

There are 0 best solutions below