Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display static google map on android imageview?

Tags:

android

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?

like image 783
Adnan Avatar asked Mar 16 '11 10:03

Adnan


People also ask

Is Google Maps API rest?

Since Google Map APIs support both json and xml , it can be safely said they they are implemented in REST.

Is Google static map API free?

The Maps Static API uses a pay-as-you-go pricing model. Requests for the Maps Static API are billed under the SKU for Static Maps. Along with the overall Google Terms of Use, there are usage limits specific to the Maps Static API. Manage your costs and usage with tools available in the Google Cloud Console.


1 Answers

Google offers the static map API for that you need an API key.

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

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&key=YOUR_API_KEY" 

StackOverflow already have some answer on how to download an image from the web in order to display it in an image view: link

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

like image 130
pcans Avatar answered Sep 30 '22 08:09

pcans