Thursday, November 21, 2013

Impact of Google Maps API v2 shutdown on Openlayers base layers and a easy solution

Finally on Nov 19 2013, Google shut down Google Maps v2 API, which was depreciated in May 19 2010 but was working continuously Nov 19. I was aware of version depreciation, but I procrastinate to upgrade till last minute because of working on too many other things. While checking my Web map (built on Openlayers, Geoserver and Google Maps as base layers (Google Maps API v2) on Nov 20, I saw two map controls one from Openlayers and other from Google Maps API also noticed that map application was unresponsive.

Looking around I found easy steps to fix it without major change in the code-

Step1) Update the Google API script link
Replace v2:
<script src=";v=2&amp;sensor=true&amp;key=YOUR_KEY " type="text/javascript"></script> 
With v3 as:
<script src=";sensor=false"></script>

Step2) Update the Google Map base layer types for Openalayers
var gmap = new OpenLayers.Layer.Google( "Google Streets",  {'sphericalMercator':true,minZoomLevel:3, maxZoomLevel:8}); 
v3 (No change)
var gmap = new OpenLayers.Layer.Google("Google Streets", {'sphericalMercator':true,minZoomLevel:3, maxZoomLevel:8});                

var gphy = new OpenLayers.Layer.Google( "Google Physical",    
          {type: G_PHYSICAL_MAP,'sphericalMercator':true,minZoomLevel:3, maxZoomLevel:8});

v3(Change type:G_PHYSICAL_MAP to type:google.maps.MapTypeId.TERRAIN )
var gphy = new OpenLayers.Layer.Google("Google Physical",    
           {type:google.maps.MapTypeId.TERRAIN,'sphericalMercator':true,minZoomLevel:3, maxZoomLevel:8});

var gsat = new OpenLayers.Layer.Google("Google Satellite",
           {type: G_SATELLITE_MAP,'sphericalMercator':true,minZoomLevel:3, maxZoomLevel:8});
v3(Change type: G_SATELLITE_MAP to type: google.maps.MapTypeId.SATELLITE )
var gsat = new OpenLayers.Layer.Google(    "Google Satellite", 
           {type: google.maps.MapTypeId.SATELLITE,'sphericalMercator':true,minZoomLevel:3, maxZoomLevel:8});

var ghyb = new OpenLayers.Layer.Google("Google Hybrid",
           {type: G_HYBRID_MAP, 'sphericalMercator':true,minZoomLevel:3, maxZoomLevel:8});
v3(Change type:G_HYBRID_MAP to type: google.maps.MapTypeId.HYBRID)    
var ghyb = new OpenLayers.Layer.Google(    "Google Hybrid",                    
           {type: google.maps.MapTypeId.HYBRID, 'sphericalMercator':true,minZoomLevel:3, maxZoomLevel:8});

Google , Google API , Google Maps , WebGIS


Post a Comment


© 2011 GIS and Remote Sensing Tools, Tips and more .. ToS | Privacy Policy | Sitemap

About Me