如何显示在Android ImageView的静态谷歌地图?静态、地图、Android、ImageView

2023-09-05 05:28:16 作者:浅浅伤痕而已﹌

我要显示在一个ImageView的一个静态的谷歌地图。类似的东西为WhatsApp的显示共享时的位置。我怎样才能做到这一点?

I want to display a static google map on an imageview. Something similar to "Whatsapp" showing while share the location. How can I do this?

推荐答案

谷歌提供的静态地图API是免费的。

Google offer the static map API for free.

您可以从网上下载一个动态配置的位图,将其存储在文件系统或存储,然后得到一个绘制的它,以便将其设置为ImageView的。

You can download a dynamically configured bitmap from the web, store it on the filesystem or on memory, then get a drawable from it in order to set it to the ImageView.

您需要根据你的坐标的URL来利用这个网址的网页加载数据。为例为200x200的位图显示了巴黎埃菲尔铁塔:

You need to generate an url from your coordinates to load the data from the web using this url. Exemple for a 200x200 bitmap showing the eiffel Tower in Paris:

String latEiffelTower = "48.858235";
String lngEiffelTower = "2.294571";
String url = "http://maps.google.com/maps/api/staticmap?center=" + latEiffelTower + "," + lngEiffelTower + "&zoom=15&size=200x200&sensor=false"

计算器已经对如何从网络,以在ImageView的显示其下载的图像部分答案:http://stackoverflow.com/search?q=imageview+url+%5Bandroid%5D

您可以在这里找到了谷歌静态地图API 的文档。

You can find here the documentation for the Google Static Maps API.

 
精彩推荐