Daw a polyline and get its length - JS w/ Google Maps

Discussion created by shaningesri on Jul 18, 2011
From, I loaded the JavaScript, which provides the function to draw a polyline and receives the line's lengh.  I followed the approach in Google Maps Layer for ArcGIS JavaScript API: Examples ( to try to add a google map layer on the top of ESRI's map.  But I can't see the google map.  The code is presented below.  If you want to try, please copy, paste it onto Notepad, and then save it as htm file.  Then, you can open it locally.  Hopefully, you can hint me something.  Thanks.
I also tried in several other samples *see my other post threads).  The common thing is that once I get ESRI's maps, I can't add google map layer on the top.
I tried another way, add ESRI maps on top of Google Maps.  It works for an ESRI dynamic layer but not for an ESRI cached tiled layer.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"

<html lang="en">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" />
  <!--The viewport meta tag is used to improve the presentation and behavior of the samples
    on iOS devices-->
  <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
   <title>Measure Distances</title>
  <link rel="stylesheet" type="text/css" href="">

  <script type="text/javascript" src="" ></script>
<script type="text/javascript" src="" ></script>

    <script type="text/javascript">

      var geometryService;
var gmap;

      function init() {
        //identify proxy page to use if the toJson payload to the geometry service is greater than 2000 characters.
        //If this null or not available the project and lengths operation will not work.  Otherwise it will do a http post to the proxy. = "/arcgisserver/apis/javascript/proxy/proxy.ashx"; = false;

        var startExtent = new esri.geometry.Extent(-80.0571,41.3697,-74.4321,44.0822, new esri.SpatialReference({wkid:4326}) );
        var map = new esri.Map("map", {extent:startExtent});
        dojo.connect(map, "onLoad", initFunctionality);

        map.addLayer(new esri.layers.ArcGISTiledMapServiceLayer(""));

        geometryService = new esri.tasks.GeometryService("");

        dojo.connect(geometryService, "onLengthsComplete", outputDistance);

              gMap = new gmaps.GoogleMapsLayer({
                visible: false,
                id: 'googlemaps'


      function initFunctionality(map) {
        var tb = new esri.toolbars.Draw(map);

        var lengthParams = new esri.tasks.LengthsParameters();

        //on draw end add graphic, project it, and get new length
        dojo.connect(tb, "onDrawEnd", function(geometry) {
          lengthParams.polylines = [geometry];
          lengthParams.lengthUnit = esri.tasks.GeometryService.UNIT_METER;
          lengthParams.geodesic = true;
          var graphic = esri.Graphic(geometry, new esri.symbol.SimpleLineSymbol()));


      function outputDistance(result) {
        dojo.byId("distance").innerHTML = dojo.number.format(result.lengths[0] / 1000) + " kilometers";


    Click and hold down on the map to draw a line that will be added to the map.  The application will then use the geometry service to project and compute the length of the line.
    <div id="map" class="claro" style="width:1024px; height:512px; border:1px solid #000;"></div>

    Distance: <span id="distance"></span>