CuriousMind
CuriousMind

Reputation: 19

Downloading a map image using Google Map using Java

What I want to do:

I want to create a little program in Java (beginner in Java here) in which I specify a GPS location and zoom level and download the map image that Google Maps is showing. Associated with this, I need to have a scale associated with the image (the size in Km of the x and y dimensions of the rectangular image).

What I know:

I know how to get the right image displayed in the browser, specifying GPS location and zoom level directly in the URL (example: https://maps.google.com/maps?f=q&hl=de&geocode=&q=48.167432,+10.533072&z=7). There should be some kind of library like urllib in Python with which I will call this URL.

How to then download this image, and how to know the area pictured in it? I actually found a formula to relate the amount of meters (or whatever unit) "contained" in a pixel (this function depends on latitude and zoom level of the map). In this case, how to know about the pixels used by the map?

Thank you for any suggestion and/or pointer!

Upvotes: 1

Views: 5954

Answers (1)

Cruncher
Cruncher

Reputation: 7812

You want to use static maps API.

https://developers.google.com/maps/documentation/staticmaps/index

Your particular map would be at URL

http://maps.googleapis.com/maps/api/staticmap?center=48.167432,10.533072&size=400x400&sensor=true&zoom=7 

as just an image. Set sensor=true if you're using a GPS sensor to find the location. Otherwise set it to false.

To read the image from this url:

Getting Image from URL (Java)

How to then download this image, and how to know the area pictured in it? I actually found a formula to relate the amount of meters (or whatever unit) "contained" in a pixel (this function depends on latitude and zoom level of the map). In this case, how to know about the pixels used by the map?

You pass pixels and zoom level into the image, so that information is all given with this solution, so your scale should be very easy to calculate.

Upvotes: 3

Related Questions