Googlemap v3 measure - convert meters to feet and acres

1.1k views Asked by At

I have a googlemap with a kml layer embedded and the code I found on google developers forum is below. It is showing meters for distance and sq meters for area. How can I change this to show feet for distance and acres for area? Any help will be appreciated. Thanks.

4046.86 sq meters in 1 acre 3.28084 feet in 1 meter

        <script type="text/javascript">

                    var polyline;
                    var polygon;
                    var map;


                    function initialize() {
                      var Trigger = new google.maps.LatLng(31.3664951, -98.5192484);
                      var myOptions = {
                        zoom: 14,
                        center: Trigger,
                        mapTypeId: google.maps.MapTypeId.HYBRID
                      };

                      map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
                      var lineOptions = {
                        strokeColor: '#ff0000',
                        strokeOpacity: 1.0,
                        strokeWeight: 3
                      }

                        var kmlLayer = new google.maps.KmlLayer({
                            url: 'http://www.website.com/KML/filename.kmz',
                            suppressInfoWindows: false,
                            map: map
                          });
                        map.setOptions({draggableCursor:'crosshair'});

                      polyline = new google.maps.Polyline(lineOptions);
                      polyline.setMap(map);
                      var gonOptions = {
                        fillColor: '#0000FF',
                        fillOpacity: 0.4,
                        strokeWeight: 0
                      };
                      polygon = new google.maps.Polygon(gonOptions);
                      polygon.setMap(map);
                      // Add a listener for the click event
                      google.maps.event.addListener(map, 'click', addLatLng);
                    }

                    /**
                     * Handles click events on a map, and adds a new point to the Polyline.
                     * Updates the encoding text area with the path's encoded values.
                     */
                    function addLatLng(event) {
                      var lpath = polyline.getPath();
                      // Because path is an MVCArray, we can simply append a new coordinate
                      // and it will automatically appear
                      lpath.push(event.latLng);
                      var gpath = polygon.getPath();
                      gpath.push(event.latLng);

                      // Update the text field
                      document.getElementById('lineLength').value = google.maps.geometry.spherical.computeLength(lpath.getArray());
                      if (gpath.getLength()>2){
                        var garray = [];
                        gpath.forEach(function(ll,num){
                          garray.push(ll);
                        });
                        // close loop.
                        garray.push(gpath.getAt(0));
                        // bug? Always return 0.
                        var a = google.maps.geometry.spherical.computeArea(garray);

                        document.getElementById('polyArea').value = a;
                      }
                    }


    </script>
1

There are 1 answers

0
geocodezip On

Use the conversion factors you have:

  • 4046.86 sq meters in 1 acre: number in sq meters * 1 acre / 4046.86 sq meters = number in acres
  • 3.28084 feet in 1 meter: number in meters * 3.28084 feet / meter = number in feet

                  // Update the text field
                  document.getElementById('lineLength').value = google.maps.geometry.spherical.computeLength(lpath.getArray()) *  3.28084; // 3.28084 feet in 1 meter
                  if (gpath.getLength()>2){
                    var garray = [];
                    gpath.forEach(function(ll,num){
                      garray.push(ll);
                    });
                    // close loop.
                    garray.push(gpath.getAt(0));
                    // bug? Always return 0.
                    var a = google.maps.geometry.spherical.computeArea(garray);
    
                    document.getElementById('polyArea').value = a / 4046.86; // 4046.86 sq meters in 1 acre