androidgoogle-mapsurlgoogle-url-shortener

Android sharing intent with google maps location and URL Shortener API


I am trying to share a location with latitude and longitude as;

String uri = "http://maps.google.com/maps?daddr=" + latLngMaps.latitude + "," + latLngMaps.longitude;

Using these lines of code:

Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                sharingIntent.setType("text/plain");
                String ShareSub = pharmacyName + "\n" + pharmacyAddress;
                sharingIntent.putExtra(Intent.EXTRA_TEXT, ShareSub + "\n" + shortURL);
                startActivity(Intent.createChooser(sharingIntent, "Share With?"));

What I want to do is:

Image taken from Whatsapp Windows app

I am using URL shortener api and converting the "http://maps.google.com/maps?daddr=" + latLngMaps.latitude + "," + latLngMaps.longitude; to goo.gl/xxxxx

It becomes like this Shared from my app

Is it possible to get that first Image's view when I share my map on Whatsapp?

If it is not, How can I shorten my link as goo.gl/maps/xxxx not goo.gl/xxxx ?


Solution

  • You need to use Google static Maps API which returns a map as an Image which you can share through intent.You can also customize static maps API like you can set marker location, set zoom level.

    Url
    https://maps.googleapis.com/maps/api/staticmap?center=Australia&size=640x400&style=element:labels|visibility:off&style=element:geometry.stroke|visibility:off&style=feature:landscape|element:geometry|saturation:-100&style=feature:water|saturation:-100|invert_lightness:true&key=YOUR_API_KEY
    

    You can also use the lighter version of google map using google map options. it is also displayed as an Image. which can be clicked and also has google map customization.