Java 调用 Google Map JavaScript API时,报错提示Exception in thread "JavaFX Application Thread" netscape.javascript.JSException: ReferenceError: Can't find variable: google
在学习Coursera上的一门数据结构课程,将课程提供的源码导入Eclipse,按照提示在google申请了API key,并在index.html中替换,index.html文件如下(除此以外,没有对源码其他地方做任何改动)
html>
<html>
<head>
<title>Simple Map!title>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="routing.css" />
head>
<body>
<div id="map">div>
<script src="https://maps.googleapis.com/maps/api/js?key=【已替换为新申请的key】&callback=initMap">script>
<script type="text/javascript" src="visual.js">script>
body>
html>
程序结构如下图所示:
正常的运行效果应该是下面这样:
但实际自己的运行效果显示如下:
控制报错:Exception in thread "JavaFX Application Thread" netscape.javascript.JSException: ReferenceError: Can't find variable: google
请问是哪里的问题
Can't find variable: google
变量没有定义,看看具体的代码遗漏了什么
该回答引用GPT:
可能是Google Map JavaScript API的key没有正确配置,请检查index.html文件中是否正确配置了API key,并且确认API key是否有效,如果API key无效,请重新申请一个新的API key。
如还有疑问,可以私信帮助解决。