未捕获的ReferenceError:未定义谷歌(索引):21初始化(谷歌地图API) [英] Uncaught ReferenceError: google is not defined (index):21 initialize ( Google Maps API )

查看:115
本文介绍了未捕获的ReferenceError:未定义谷歌(索引):21初始化(谷歌地图API)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继续在控制台中收到此错误未捕获的ReferenceError:未定义Google。已经做了一段时间但没有运气。任何帮助非常感谢。提前致谢

Keep on getting this error in the console "Uncaught ReferenceError: google is not defined". Been doing it for a while now but no luck. Any help greatly appreciated. Thanks in advance

<!DOCTYPE html>
<html>
 <head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
  html { height: 100% }
  body { height: 100%; margin: 0; padding: 0 }
  #map-canvas { height: 100% }
  </style>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"</script>
<script type="text/javascript"
  src="https://maps.googleapis.com/maps/api/js?sensor=false">
  </script>
<script type="text/javascript">
   function initialize(location) {

  console.log(location);

  var mapOptions = {

      center: new google.maps.LatLng(location.coords.latitude, location.coords.longitude),
      zoom: 8
    };
        var map = new google.maps.Map(document.getElementById("map-canvas"),
        mapOptions);
  }

  $(document).ready(function()
  {
  navigator.geolocation.getCurrentPosition(initialize);
  });
  </script>
  </head>
  <body>
  <div id="map-canvas"/>
  </body>
</html>


推荐答案

脚本中存在问题代码中的声明。您错过了关闭脚本标记 jquery ,因此谷歌地图js无法正确加载。

There was problem in script declaration in your code. You missed to close script tag for jquery and hence google map js wasn't load properly.

只需在下方更改...

Just change below...

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"**[[Problem is here]]**</script>
<script type="text/javascript"
  src="https://maps.googleapis.com/maps/api/js?sensor=false">
  </script>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript"
  src="https://maps.googleapis.com/maps/api/js?sensor=false">
  </script>

它应该可以正常工作。

这是演示

这篇关于未捕获的ReferenceError:未定义谷歌(索引):21初始化(谷歌地图API)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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