我希望原点是数字,目标是字符串,但是出现此错误。 InvalidValueError:属性来源中:不是字符串;而不是LatLng或LatLngLiteral:属性lat:不是数字;和未知属性lat
asdasd
calculateAndDisplayRoute(directionsService, directionsDisplay) {
this.geolocation.getCurrentPosition().then((resp) => {
resp.coords.latitude
resp.coords.longitude
}).catch((error) => {
console.log('Error getting location', error);
});
let watch = this.geolocation.watchPosition();
watch.subscribe((data) => {
this.lat=data.coords.latitude;
this.long=data.coords.longitude;
});
var directionsService = new google.maps.DirectionsService;
var directionsDisplay = new google.maps.DirectionsRenderer;
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 5,
center: {
lat: +this.lat,
lng: +this.long
}
});
directionsDisplay.setMap(map);
directionsService.route({
origin: {
lat:this.lat,
lng:this.long
},
destination: this.End,
travelMode: 'DRIVING'
}, function(response, status) {
if (status === 'OK') {
directionsDisplay.setDirections(response);
} else {
window.alert('Directions request failed due to ' + status);
}
});
}