两个位置之间的距离-Google地图 [英] Distance between two locations - Google Maps

查看:117
本文介绍了两个位置之间的距离-Google地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to find the location between two points using google maps. Here is the code that I'm working with:

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));
        }

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

This is the error I get from the console:


未被捕获的TypeError:无法读取未定义的属性'spherical'

Uncaught TypeError: Cannot read property 'spherical' of undefined


推荐答案

如果尚未这样做,请在< script> 标记
<$ c中显式添加几何库$ c> src = http://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false>

If you haven't done so, explicitly add the geometry library in your <script> tag src="http://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false">

这篇关于两个位置之间的距离-Google地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆