【发布时间】:2017-01-13 02:38:26
【问题描述】:
我制作了一个简单的应用程序来在地图上显示我当前位置和一个默认位置之间的距离和路线。我设法在屏幕上获取地图(在 Galaxy S4 上,但我无法在平板电脑 Galaxy Tab 4 上获取),但我遇到了下一个问题:
- 我不能用两根手指缩放,小部件 +/- 效果很好,但是当我尝试用手指缩放时,只得到一个没有任何地图的颜色 div,如果我按 + 或 - 小部件地图回来李>
- 我无法向任何方向移动地图,它是静态的。我想用手指向各个方向移动
- 我无法显示标记,当我点击标记时没有任何反应。当我在 Ionic 服务上单击 PC 时效果很好。我对标记的第二个问题是我应该点击/单击以显示标记,我想一直在线
- 我无法获得在屏幕上书写的距离,尽管按两次按钮时已显示距离。
这是我的代码,有人可以帮助我吗?谢谢。
index.html
<!DOCTYPE html>
<html>
<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' *; style-src 'self' 'unsafe-inline' *">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
</head>
<body ng-app="inception">
<ion-nav-view>
<ion-header-bar class="bar bar-header bar-calm">
<h1 class="title text-center">Test</h1>
</ion-header-bar>
<ion-content class="has-header">
<div class = "row colors-back">
<div class = "col col-100">
<div class="row" ng-if="locCtr.showRoute">
<div class="col-100 text-center">Distance: {{locCtr.showDistance}}</div>
</div>
<div id="map" draggable="true"></div>
</div>
</div>
</ion-content>
</ion-nav-view>
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/ionic-material/dist/ionic.material.min.js"></script>
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDVYeH02dc5EyoYaqpYSFsogSlkOx2S2o4&sensor=true" async defer></script>
<script src="cordova.js"></script>
<script src="app/application.js"></script>
<script src="app/controllers/mainController.js"></script>
<script src="app/controllers/locationController.js"></script>
</body>
</html>
控制器
(function() {
'use strict';
angular
.module('inception')
.controller('locationController', locationController);
locationController.$inject=['$cordovaGeolocation'];
function locationController($cordovaGeolocation) {
var vm = this;
vm.getRoute = getRoute;
function getRoute() {
vm.showData = false;
vm.route = {};
var options = {timeout: 10000, enableHighAccuracy: true};
$cordovaGeolocation.getCurrentPosition(options).then(function(position){
vm.latOrigin = position.coords.latitude;
vm.longOrigin = position.coords.longitude;
var directionsService = new google.maps.DirectionsService;
var directionsDisplay = new google.maps.DirectionsRenderer;
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 15,
center: {lat: vm.latOrigin, lng: vm.longOrigin}
});
directionsDisplay.setMap(map);
directionsService.route({
origin: vm.latOrigin+","+vm.longOrigin,
destination: "44.008115,20.896861",
travelMode: 'WALKING'
}, function(response, status) {
if (status === 'OK') {
directionsDisplay.setDirections(response);
vm.route = response.routes[0];
vm.showDistance = vm.route.legs[0].distance.text;
} else {
window.alert('Directions request failed due to ' + status);
}
});
});
vm.showRoute = true;
}
}
})();
css
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
.scroll {
height: 100%;
}
#map {
width: 100%;
height: 300px;
}
【问题讨论】:
标签: javascript google-maps ionic-framework ngcordova