我被分配了此任务来更正googlemaps路线网址。
目前,地图从当前的GeoLocation引导用户,而不是输入的邮政编码(新位置... lat和long)。
这是我的ViewModel
function ViewModel() {
var self = this;
self.map = null;
self.currentLocation = {
latitude: 0,
longitude: 0
};
self.geocode = function () {
if (!self.isValid()) {
self.zipCode(self.previousZipCode);
} else {
self.previousZipCode = self.zipCode();
}
// Take the updated zip code and geocode it into lat/long
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': self.zipCode() }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
lat = results[0].geometry.location.lat();
lng = results[0].geometry.location.lng();
var newLocation = {
latitude: lat,
longitude: lng
};
if (self.currentLocation.latitude == newLocation.latitude && self.currentLocation.longitude == newLocation.longitude) return;
self.currentLocation = newLocation;
self.reload();
然后,在View ...中我只是不知道如何在我的标记中获取currentLocation值(View)
<a data-bind="attr: {'href' : 'https://www.google.com/maps/dir/**Current+Location**/' + Latitude + ',' + Longitude, 'data-track' : 'Find a Location', 'data-track-action' : 'directions', 'data-track-label' : ItemName }" target="_blank" class="locations-icon flex-item uppercase">
<i class="material-icons">directions</i><br />
directions
</a>