Google Maps API - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Google Maps Zoom

Google Maps Zoom

shape Introduction

The chapter demonstrates about the Google Maps Zoom and following topics covered.
  • Maximum Zooming Imagery

Maximum zooming imagery

shape Description

Various zooming levels are provide by Google Maps API for viewing a map. The levels 0-18 gives the available roadmap imagery. For a remote locations at high zooming levels the satellite imagery may not available always, by using the MaxZoomService object user can know the maximum zooming level for a preferred location. A callback method is used to execute the user request and process the result(s). Call the getMaxZoomAtLatLng() object for requesting a MaxZoomService. Following are the parameters for getMaxZoomAtLatLng() for executing a callback function.

shape Example

The below example demonstrate the simple code for Maximum Zooming imagery for a particular location on a map using the LatLng co-ordinate values. [c] <!DOCTYPE html> <html> <head> <title>Maximum Zoom imagery service</title> <meta name="viewport" content="initial-scale=1.0, user-scalable=no"> <meta charset="utf-8"> <style> html, body { height: 100%; margin: 0; padding: 0; } #map { height: 100%; } </style> </head> <body> <div id="map"></div> <script> var map; var maxZoomService; var infoWindow; function initMap() { map = new google.maps.Map(document.getElementById('map'), { zoom: 11, center: {lat: 17.2400, lng: 78.4800}, mapTypeId: google.maps.MapTypeId.HYBRID }); infoWindow = new google.maps.InfoWindow(); maxZoomService = new google.maps.MaxZoomService(); map.addListener('click', showMaxZoom); } function showMaxZoom(e) { maxZoomService.getMaxZoomAtLatLng(e.latLng, function(response) { if (response.status !== google.maps.MaxZoomStatus.OK) { infoWindow.setContent('Error in MaxZoomService'); } else { infoWindow.setContent( 'The maximum zoom at this location is: ' + response.zoom); } infoWindow.setPosition(e.latLng); infoWindow.open(map); }); } </script> <script src="https://maps.googleapis.com/maps/api/js?key=&signed_in=true&callback=initMap" async defer> </script> </body> </html> [/c]

Summary

shape Key Points

  • For a Map Type imagery map titles are provide at various zoom levels by Google Maps API.
  • Developer need to pass a call back method to execute completion of the request.

shape Programming Tips

  • Copy the API key obtained from Google Maps API and paste using the JavaScript tag in the code for loading Maps.
  • Set the required Map Properties for better output.
  • Make sure the latitude and longitudes of the required location mentioned to be correct.