Tuesday, June 01, 2010

Moving from Google Maps 2 to Google Maps 3

After playing with version 3 of the Google Maps API and trying to convert my ScratchPad application, I’m pretty impressed. It’s a much more consistent API than version 2 and provides quite a few new features. But one thing is for sure, converting an application from version 2 to version 3 will be a big chunk of work. Pretty much every line will need rewriting.

So I thought I’d provide a little crib sheet to help people who are trying to upgrade. I don’t claim that this list is in any way complete. I’ll update it as I find more things out, but even so I only intend it to be a pointer to the right class/method to use. In most cases the way methods or classes are used has also changed. If you have any other information to add, please add a comment.

Google Maps version 2 Google Maps version 3
GMap2 class google.maps.Map class
GMap2.disableDoubleClickZoom() MapOptions.disableDoubleClickZoom:true passed to Map constructor or Map.setOptions()
GMap2.getDragObject().setDraggableCursor() MapOptions.draggableCursor passed to Map constructor or Map.setOptions()
GMap2.addOverlay() Call setMap() on the layer to add
GMap2.clearOverlays() ???
GMap2.removeOverlay() Call setMap(null) on the layer to remove
GLatLng class google.maps.LatLng class
GMarker class google.maps.Marker class
GMarker.bindInfoWindowHtml() google.maps.InfoWindow class, but you need to manually open the info window using

    google.maps.event.addListener(marker, 'click', function () {
    infoWindow.open(map, marker);
  });

GEvent.bind(), GEvent.addListener google.maps.event.addListener(), although it doesn’t seem possible to bind the event to particular object instance (where the keyword this can be used in the event handler)
GEvent.removeListener() google.maps.event.removeListener()
GNavLabelControl class ???
GAdsManager class ???
GGeoXml class google.maps.KmlLayer class
GGeoXml.load event ???
GGeoXml.getDefaultCenter() KmlLayer.getDefaultViewport().getCenter()
GStreetviewOverlay class This is now integrated into the map, pass streetViewControl: true into MapOptions to make it appear
GClientGeocoder class google.maps.Geocoder class
GClientGeocoder.getLatLng() Geocoder.geocode()
GPolyline class google.maps.Polyline class
GPolyline.getLength() There is no direct replacement, but this forum post discusses how to implement something similar yourself.
GPolyline.getVertexCount() Polyline.getPath().length()
GDirections class google.maps.DirectionsService class to query for directions, google.maps.DirectionsRenderer class to render them on a map
GDirections.load() DirectionService.route()
GDirections.loadFromWaypoints() DirectionsRequest.waypoints property
GDirections.clear() No equivalent
GTrafficOverlay class google.maps.TrafficLayer class
GLayer class ??? – This is in the API issues database, star it if you want it implemented
GTileLayerOverlay class ???

No comments: