这个问题让我疯狂了一个星期:
Google地图适用于浏览器但不适用于设备,我已删除所有plugins
和Android平台,然后重新安装platform
和plugins
,但地图不起作用在设备上。代码:
的index.html
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8">
<title>Ionic App</title>
<meta name="viewport" content="width=device-width,height=device-height, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta http-equiv="Content-Security-Policy" content="default-src *; script- src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src 'self' 'unsafe-inline' *">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<link rel="icon" type="image/x-icon" href="assets/icon/favicon.ico">
<link rel="manifest" href="manifest.json">
<meta name="theme-color" content="#4e8ef7">
<!-- un-comment this code to enable service worker
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('service-worker.js')
.then(() => console.log('service worker installed'))
.catch(err => console.error('Error', err));
}
</script>-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="build/main.css" rel="stylesheet">
<!-- Ionic's root component and where the app will load -->
<ion-app></ion-app>
<!-- The polyfills js is generated during the build process -->
<script src="build/polyfills.js"></script>
<!-- The vendor js is generated during the build process
and contains all code in `node_modules` -->
<script src="build/vendor.js"></script>
<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyAa1urkW-Vbj-K 82Ry9jw8rPHOrXVZ_9SU"></script>
<!-- The bundle js is generated during the build process -->
<script src="build/main.js"></script>
<!-- cordova.js required for cordova apps -->
<script src="cordova.js"></script>
</body>
</html>
请帮忙!
修改
编辑2:
我已经找到了问题的来源,这部分代码可以正常工作并正确记录:
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(this.showMap, this.showError, { enableHightAccuracy: true })
console.log(google);
}
但是“this.showMap”函数不会执行。
有什么建议吗?