Android sharing intent with google maps location and URL Shortener API

三世轮回 提交于 2019-12-08 05:01:12

问题


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:

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

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 ?


回答1:


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.

visit my website for learnning Kotlin and Android - Developine



来源:https://stackoverflow.com/questions/47522022/android-sharing-intent-with-google-maps-location-and-url-shortener-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!