Using google static maps
The article describes the main possibilities of using static Google maps based on the author’s own experience.Google provides two options for using its map services.
- Google maps, based on the javascript API, provides various possibilities for displaying various geographic information.
There is a well-designed and structured class library, the documentation for which can be found at the following links:
English , Russian and play in the sandbox

- And the second option provides much less functionality, but sometimes only it is possible to use it.
These are static cards. In general terms, using this service, you can simply display a certain map, and the maximum size of the resulting image is 512x512 pixels. Also, along with the coordinates, it is permissible to indicate the zoom level and add additional labels.

')
Both types of services have their advantages and should be used in well-defined areas. But in order to correctly determine when to use which cards, you need to know all the possibilities.
This article is about static maps; you can talk about normal maps another time.
Static google maps
To work with the Google API, you need to
register for free and get an API key, which is then used in most cases.
Also, developers are provided with full information on using the Static Maps API, which is located at the following addresses:
English and
Russian .
There are cases when you really want to use maps dynamically in a project, but there is no possibility to use regular Google maps. This is mainly due to the presence of JavaScript support in the target platform.
A good example is J2ME, a very decent networking experience, but there is absolutely no way to use JavaScript. And therefore, static maps is one of the best solutions.
Consider a hypothetical mobile service: Users can freely add to the database their bars, cafes and other catering establishments, after which, based on the entered address, the coordinates of the place are calculated and then on the page with its description, you can immediately see the map.
It can be seen that the task is divided into two subtasks:
- Get the coordinates at;
- Get a map by coordinates.
You can also add another third subtask, organize navigation on the map.
Getting coordinates at
This procedure is called geocoding, there is also reverse-geocoding, when an address is given on the basis of coordinates, but we will not consider it.
A detailed description is located at the following addresses:
English and
RussianFor a successful geocoding ʻa need only two things address in a format understandable by Google and API key.
If the first is simple, that the term clarity for Google requires clarification. The fact is that for a guaranteed successful geocoding ʻa, the entered address should be as complete and accurate as possible, because, for example, in the same America you can easily find both Moscow and Paris. There is also a requirement that the address is useful, for example, if the street is called “Red Arrows”, then at the request “Kr. Arrows ”most likely nothing will be found.
Then everything is simple, the coordinates are provided in the form of a pair of values, latitude and longitude and you need to send the address of interest to the Google service
http://maps.google.com/maps/geo specifying the following parameters:
- q - Address to be geocoding `y;
- key - your API key;
- output - Required response format, the following values are possible: xml, kml, csv or json.
An example of getting a random address in Moscow:
http://maps.google.com/maps/geo?q=Russia%20Moscow%20Tverskaja%2011&output=json&key=abcdefgUPD 1 I transfer my comment to the article, I think here it is the place.
___________________
There are some more optional parameters, for example the format parameter, to get the image not in the default GIF, but in JPG, or PNG (my favorite).
Let me give you all the rest:
maptype - The type of map requested may be other than mobile, satellite, terrain, hybrid.
path - You can specify the line to draw between two points, and you can specify a lot of points. But this option fits toko only if you build these lines manually, since you cannot build a serious map with your hands, and it doesn’t automatically take into account streets, rivers, etc., it just draws a line.
Although it is possible to get a path from one point to another taking into account all this, but only when using the usual JS API.
The coordinates of the nodal points are again separated by the pipe symbol "|".
Example: path = rgba: 0xff0000ff, weight: 5 | 40.737102, -73.990318 | 40.749825, -73.987963 | 40.752946, -73.987384 | 40.755823, -73.986397
span - The parameter is taken into account only if the zoom is not specified, so with the help of the span you can specify the size of the displayed area. For example, center = 40.714728, -73.998672 & span = 20.20 will display the center of Manhattan and the area around the size of 20x20 degrees.
frame - If present, a blue frame 5 pixels wide will be shown around the map.
sensor - Marked as required in the current version. As I understand it, you need to specify it to be true if your own coordinates come from a moving device.
Well, the last one,
hl - Allows you to explicitly specify the language to display all the names on the map. Understands a limited number of locale names.
___________________
I think it will not be difficult to parse the data, especially since in different programming languages this is done differently, and I will not dwell on this.
As a result, we got either zeros, if something went wrong, or the coordinates of the address that need to be saved to the database, since every time doing geocoding is very expensive.
Getting a map by coordinates
This second part of the task arises as soon as we need to display a map. In principle, everything is also simple here, you need to use the second Google service:
http://maps.google.com/staticmapIt takes the following parameters:
- center - Coordinates of the map center (format 37.6095373,55.7606587);
- zoom - The level of map approximation, in general, a number from 1 to 15;
- size - The size of the requested image is transmitted as WxH, for example 300x200, and the maximum values are defined as 512x512 pixels;
key - your API key; - maptype - The type of the map, there are several possible options, but in this case, the most appropriate value is mobile;
- markers - Using markers, you can add additional labels to the map, for example, to show the surrounding cafes. The format of use is as follows:
{latitude}, {longitude}, {color} {letter} are separated markers with a pipe symbol "|"
Example:
markers = 40.702147, -74.015794, blues | 40.711614, -74.012318, greeng
Two markers are created here, the first blue with the letter S, the second green with the letter G.
As a result of the query generated by these rules, we get a regular image that is not difficult to display.
There is still the question of organizing navigation, but these are details of the application, in the simplest case, links to the neighboring coordinates and to increase / decrease (zoom + 1, zoom-1) can be positioned next to the map and each time load a new map, or organize something more complicated with asynchronous requests and map redrawing; in principle, on J2ME it is not very difficult.
2009.06.12
Pavel Osipov