Map types in Google Maps

We continue with the development of Google maps, we see the types of map or types of view, satellite, streets and hybrid map.

When developing with Google Maps we can choose the type of map that users will see, among the different predefined views such as satellite view, street view or hybrid view (satellite and streets in semi-transparent mode).

To define the map type in a Google map we have the setMapType() method of the GMap2 class. The setMapType() method receives the type of map you want to see. In principle there are the following types of map:

G_NORMAL_MAP

It is for a normal map, which is the political map, with the names of locations. This map is defined by default. At first the different countries appear, but if we zoom in we will see the important cities, roads, etc. and if we zoom in on a population we will see the names of the streets, squares, neighborhoods, etc.

G_SATELLITE_MAP

This map allows you to see the world with images taken from satellite.

G_HYBRID_MAP

This map combines the satellite view and the normal view. The different locations, streets, etc. are painted over the satellite photos.

Let’s look at a Google map in which we define the type of map. We show a satellite view in this case.




Google Maps API Example





With this code we will have a satellite view of Barcelona centered on the square where the statue of Columbus is pointing with his finger. A couple of things to watch:

  • In the line that loads the Google Maps API we have to replace “AQUI-TU-CLAVE” by the API user key provided by Google when registering to use their maps on our website. http://maps.google.com/maps?file=api&v=2&key=HERE-YOUR-KEY
  • The line map.setMapType(G_SATELLITE_MAP); is where we load the view type.

Note: There are other previous articles where we have explained additional Google Maps topics that you should know to understand this code:

Now, if we want a hybrid map, we will only have to change the line:

map.setMapType(G_SATELLITE_MAP);

For this other line, where we specify another type of map:

map.setMapType(G_HYBRID_MAP);

We can also try to remove that line where we specify the type of map. We’ll see how the street map comes out then. It is the same as if we specified the normal map type.

map.setMapType(G_NORMAL_MAP);

See also  The algorithm, an initiation to programming
Loading Facebook Comments ...
Loading Disqus Comments ...