【发布时间】:2017-03-18 20:30:41
【问题描述】:
我正在编写一个应用程序来跟踪当前位置并使用 google.maps.Polyline 绘制它。 问题是即使停止,当前位置也会发生变化。直走时也会发生这种情况。像这样:
这是代码:
var watchOptions = { timeout: 1000, enableHighAccuracy: false // get the same behaviour with 'true' };
var track = []; // coordinates to draw with Polyline
watch = $cordovaGeolocation.watchPosition(watchOptions);
changeMarker(myMarker, latLng);
watch.then(
null,
function(err) {
console.log(err);
},
function(position) {
var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
// push current position to array
track.push({ lat: position.coords.latitude, lng: position.coords.longitude});
var trackPath = new google.maps.Polyline({
path: track, // pass coordinates
strokeColor: "#2980b9",
geodesic: true,
strokeOpacity: 1.0,
strokeWeight: 2
});
// draw on map
trackPath.setMap($scope.map);
【问题讨论】:
标签: cordova google-maps ionic-framework geolocation