Hi..is that possible, suppose if I search any random city in google map and google map automatically set that zoomlevel ?I mean How can I set zoom level of google map automatically ?
I am using google map API.
please help me.
Hi..is that possible, suppose if I search any random city in google map and google map automatically set that zoomlevel ?I mean How can I set zoom level of google map automatically ?
I am using google map API.
please help me.
When you instantiate a google maps object using:
new google.maps.Map(domElement, options)
You can can use options
to set (among other things) the zoom level.
The default zoom level can be set using { zoom: 14 }
for example.
After you create you google maps object, you can change the zoom level using setZoom()
var myMap = new google.maps.Map(
document.getElementById('map-canvas'),
{ zoom : 14 }
);
myMap.setZoom(12);
<!DOCTYPE html "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps JavaScript API Example</title>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=abcdefg&sensor=true_or_false"
type="text/javascript"></script>
<script type="text/javascript">
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
map.setUIToDefault();
}
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<div id="map_canvas" style="width: 500px; height: 300px"></div>
</body>
</html>
The map.setCenter() function can be used to set the zoom level i.e map.setCenter(GLatLng coordinate, zoom level)
In summary, you use a Geocoder object to getLocations by a query string (", "). Then use a returned PlaceMarker object to define a LatLngBounds object. Use the LatLngBounds object as a paramter for getBoundsZoomLevel to set the zoom level.