gpt4 book ai didi

javascript - 尝试在 Android 应用程序中使用 google.maps.geocoder 时出现 'google is not defined' 错误

转载 作者:行者123 更新时间:2023-11-29 20:15:36 25 4
gpt4 key购买 nike

我有一个 ionic cordova Android 应用程序,我正在尝试使用 Google map API。具体来说,我想使用地理编码器功能。在我的 Cordova Android 应用程序代码中,我有一行代码可以访问地理编码器:

var geocoder = new google.maps.Geocoder();

这行代码在"file"中并抛出错误:“ReferenceError google is not defined”。

我在 index.html 文件中添加 google maps api,如下所示:

<!DOCTYPE html>
<html ng-csp="">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<meta http-equiv="Content-Security-Policy"
content="default-src *;
script-src 'self' 'unsafe-inline' 'unsafe-eval'
127.0.0.1:*
http://192.168.1.254
maps.googleapis.com
autolinkmaker.itune.apple.com
http://*.itunes.apple.com
http://*.googleapis.com
http://*.maxplatform.com
https://*.itunes.apple.com
https://*.googleapis.com
https://*.maxplatform.com
;
style-src 'self' 'unsafe-inline'
127.0.0.1:*
http://192.168.1.254
maps.googleapis.com
autolinkmaker.itune.apple.com
http://*.itunes.apple.com
http://*.googleapis.com
http://*.maxplatform.com
https://*.itunes.apple.com
https://*.googleapis.com
https://*.maxplatform.com
">

<title></title>

<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">

<link href="https://fonts.googleapis.com/css?family=Open%20Sans%3A300%2C600%2C700" rel="stylesheet" type="text/css">

<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>

<script src="js/ng-cordova.min.js"></script>
<script src="js/parse-1.6.7.min.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>


<script src="js/app.js"></script>
<script src="js/controllers/appctrl.js"></script>
<script src="js/controllers/sharectrl.js"></script>
<script src="js/controllers/homectrl.js"></script>
<script src="js/controllers/tourctrl.js"></script>
<script src="js/controllers/newsctrl.js"></script>
<script src="js/controllers/friendsctrl.js"></script>
<script src="js/controllers/discoverctrl.js"></script>
<script src="js/controllers/watchlistctrl.js"></script>
<script src="js/controllers/trailerctrl.js"></script>
<script src="js/controllers/settingsctrl.js"></script>

<script src="lib/angular-base64/angular-base64.min.js"></script>
<script src="lib/angular-resource/angular-resource.min.js"></script>
<script src="lib/angular-animate/angular-animate.min.js"></script>
<script src="lib/angular-messages/angular-messages.min.js"></script>
<script src="lib/ionic-rating/ionic-rating.min.js"></script>
<script src="lib/ion-google-place/ion-google-place.js"></script>

<script src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>

</head>

<body ng-app="cuesApp" ng-cloak="">
<ion-nav-view>
</ion-nav-view>
</body>
</html>

我不明白为什么 google 是未定义的?

最佳答案

您在所有其他脚本之后加载 Google Maps API,因此当您尝试使用 google.maps 时它还不存在。

移动<script src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>到顶部来修复它。

关于javascript - 尝试在 Android 应用程序中使用 google.maps.geocoder 时出现 'google is not defined' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33962427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com