谷歌地图加载错误“谷歌”未定义

时间:2013-05-21 04:50:20

标签: javascript google-maps

好吧,我在加载地图时遇到问题,此部分会将“google”显示为undefined

var polyline = [
    new Google.map.LatLng(3.032617, 101.376),
    new Google.map.LatLng(3.03255, 101.3759),
    new Google.map.LatLng(3.032467, 101.3758),
    new Google.map.LatLng(3.031867, 101.3753),
    new Google.map.LatLng(3.0318, 101.3753)
];

var polylineopts = {
  path: polyline,
  map: map,
  strokecolor: 'blue',
  strokeopacity: 1.6,
  strokeweight: 3,
  geodesic: true
};

var poly = new google.maps.Polyline(polylineopts);

1 个答案:

答案 0 :(得分:2)

我预计错误是“Google”未定义。 Javascript区分大小写。

应该是:

var polyline = [
    new google.maps.LatLng(3.032617, 101.376),
    new google.maps.LatLng(3.03255, 101.3759),
    new google.maps.LatLng(3.032467, 101.3758),
    new google.maps.LatLng(3.031867, 101.3753),
    new google.maps.LatLng(3.0318, 101.3753)
];

var polylineopts = {
  path: polyline,
  map: map,
  strokecolor: 'blue',
  strokeopacity: 1.6,
  strokeweight: 3,
  geodesic: true
};

var poly = new google.maps.Polyline(polylineopts);

working example