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.
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.
See: How to get Google Maps API to set the correct zoom level for a country?
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.
You can ask for the highest zoom possible for a certain geoposition: https://developers.google.com/maps/documentation/javascript/maxzoom
I've integrated the call after creating the map. So, while the map loads it also requests the max zoom level, and it resets the zoom level on the map only if it is lower than the map's zoom level:
this.map = this.createMap(this.el, this.initPosition);
var maxZoomService = new google.maps.MaxZoomService();
maxZoomService.getMaxZoomAtLatLng(this.initPosition, _.bind(function(response) {
if (response.status != google.maps.MaxZoomStatus.OK) {
return;
} else {
console.log("GoogleMapView maxzoomlevel is " + response.zoom);
if (response.zoom < this.map.getZoom()) {
this.map.setZoom(response.zoom);
}
}
}, this));
<!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&v=2&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)