Static Map
The
StaticMap lets you embed a Google Maps image on your webpage without requiring JavaScript or any dynamic page loading.
The result is an image, with the format we decide (gif, jpg, or png), that doesn't allow any kid of interaction.
The working method with the Static Map is very similar to the one with normal GMap. In fact, most of the properties, such as GoogleKey, CommercialKey, Height, Width, etc, are exactly the same.
The most important different properties are:
- mapType: enum of type MapType, that allows us to select the type of map between "roadmap", "satellite", "hybrid" and "terrain".
- isMobile: set it to true is your application is going to work on a mobile device.
- format: enum of type FormatEnum, that allows us to decide the format for the image (gif, jpg, or png).
- visiblePoints: specifies one or more locations that should remain visible on the map, though no markers or other indicators will be displayed. Use this parameter to ensure that certain features or map locations are shown on the static map.
- Alt: defines the Alt for the "img" of HTML.
- sensor: specifies whether the application requesting the static map is using a sensor to determine the user's location.
We can add a StaticMarker (equivalent to the GMarker) and a StaticPath (equivalent to the GPolyline) to the Static Map, using the "addStaticGMarker" and "addStaticPath" methods.
In all the cases where you set a GLatLng you can set a latitude or longitude coordinates or set an Address using the "
optionalStringValue" property (see the example).
Code.aspx
<cc1:StaticGMap ID="StaticGMap1" runat="server" Width="500" Height="500" Language="en"
format="png32" />
Code.aspx.cs
GLatLng latLng = new GLatLng(41, -7);
int colorEnumLength = 11;
int sizeEnumLength = 3;
double latStep = -1;
double lngStep = 0.4;
string msg = "Subgurim Google Maps";
int iLat = 0;
int iLng = 0;
Random r = new Random();
foreach (char c in msg)
{
if (c == ' ')
{
iLat++;
continue;
}
GLatLng latlngAux = latLng + new GLatLng(latStep * iLat + r.NextDouble() * 0.4, lngStep * iLng);
int randomColor = r.Next(colorEnumLength);
StaticGMarker.ColorEnum color = (StaticGMarker.ColorEnum)randomColor;
int randomSize = r.Next(2, sizeEnumLength);
StaticGMarker.SizeEnum size = (StaticGMarker.SizeEnum)randomSize;
StaticGMarker staticGMarker = new StaticGMarker(latlngAux, size, color, c);
StaticGMap1.addStaticGMarker(staticGMarker);
iLng++;
}
//StaticGMap1.GZoom = 5;
StaticPath path = new StaticPath();
path.colorNet = Color.FromArgb(255, 0, 80);
path.weight = 5;
path.alpha = 150;
path.points.Add(new GLatLng(41, -5));
path.points.Add(new GLatLng(41, -4));
path.points.Add(new GLatLng(40, -4));
path.points.Add(new GLatLng(39, -2));
StaticGMap1.addStaticPath(path);