Problem:
I was given a project where the client switched from using http to https. Everything worked fine except for their Google Maps page. The page had a warning in IE about unsecure mixed content. This was because Google Maps was pulling from an http (unsecured) address. It turns out that the Map was using version 2 of Google Maps API which does not support https. Only version 3 does.
Solution:
Don’t be fooled into thinking this is a straight forward, simple upgrade. It is not. This solution is just a log of what I did to get the site from v2 up to v3. It is in no way a complete guide. The site used EWindow instead of the infoWindow because of its customized look. So I guess the following could be a rough step-by-step guide to converting the Ewindow script to v3.
In general you’ll need to replace all “G” prefixes like “GSize” with “google.maps” like “google.maps.Size”.
Replace GSize with google.maps.Size
Replace GLatLng with google.maps.LatLng
Replace GPoint with google.maps.Point
Replace GOverlay with google.maps.Overlay
Replace GLatLng with google.maps.LatLng
Replace GPoint with google.maps.Point
Replace GOverlay with google.maps.Overlay
Replace “new google.maps.Overlay” with “new google.maps.OverlayView()”
Take out or replace GBrowserIsCompatible. There is no equivalent function in v3.
Replace
with something like:
Replace a custom icon marker using the icon-complex example:
http://code.google.com/apis/maps/documentation/javascript/examples/icon-complex.html
http://code.google.com/apis/maps/documentation/javascript/examples/icon-complex.html
Before the change:
After:
Replace getPoint to getPosition
For infoWindowAnchor I could not find an equivalent so I scratched the whole calculation and just put in a hard coded value.
Replace initialize:
With onAdd:
Replace map.addOverlay(object) by moving a similar call to within the object.
To this within the object:
Replace map.getPane()
With this:
Replace this.redraw
with this.draw
Replace Overlay.getZindex
I could not find an equivalent to getZIndex so, again, it’s somewhat hard coded.
Replace this.map.fromLatLngToDivPixel
With this:
Replace map.panBy(Size) to map.panBy(x:number, y:number)
With this:
A very helpful site was one that made google maps compatible for both versions:
http://notebook.kulchenko.com/maps/google-maps-using-multiple-api-versions
http://notebook.kulchenko.com/maps/google-maps-using-multiple-api-versions
And of course the Google Maps v3 Examples and API docs helped a great deal. It may also help to look at version 2 of the API so that you can try and find something equivalent.
I uploaded a converted EWindow.js for whoever needs a google maps v3 version of EWindow.
No comments:
Post a Comment