25

我正在尝试使用谷歌地图找到两点之间的位置。这是我正在使用的代码:

function initialize() {
          var myOptions = {
            center: new google.maps.LatLng(36.8813329,-103.6975488),
            zoom: 4,
            mapTypeId: google.maps.MapTypeId.ROADMAP
          };
          var map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);

           var impactCoordinates = [
              new google.maps.LatLng(37.772323, -122.214897),
              new google.maps.LatLng(34.1633766,-81.6487862),
                             ];
            var ImpactPath = new google.maps.Polyline({
              path: impactCoordinates,
              strokeColor: "#FF0000",
              strokeOpacity: 1.0,
              strokeWeight: 2
            });

            ImpactPath.setMap(map);

            var loc1 = new google.maps.LatLng(37.772323, -122.214897);
            var loc2 = new google.maps.LatLng(34.1633766,-81.6487862);

            alert(google.maps.geometry.spherical.computeDistanceBetween(loc1, loc2));
        }

这是我从控制台得到的错误:

未捕获的类型错误:无法读取未定义的属性“球形”

4

1 回答 1

58

如果您还没有这样做,请在<script>标签 中显式添加几何库src="http://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false">

于 2012-04-18T14:17:14.410 回答