Googlemap v3测量 - 将米转换为英尺和英亩

时间:2013-12-16 03:56:21

标签: google-maps measurement

我有一个嵌入了kml图层的googlemap,我在谷歌开发者论坛上找到的代码如下。它显示距离的米和面积的平方米。如何更改此项以显示距离和英尺面积的英尺?任何帮助将不胜感激。感谢。

占地1英亩,面积4046.86平方米 1米处3.28084英尺

        <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 个答案:

答案 0 :(得分:0)

使用您拥有的转换因子:

  • 1英亩4046.86平方米:平方米数* 1英亩/ 4046.86平方米=以英亩为单位
  • 1米内3.28084英尺:以米为单位的数字* 3.28084英尺/米=以英尺为单位的数字

                  // 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