我正在嘗試為我的vue.js應用設置地址解析。我沒有使用任何第三方庫,只有通過npm安裝的google地圖。調用地址解析方法時,會引發錯誤,指出屬性位置意外。我已經嘗試過“位置”,“ latlng”,坐標本身等等。經度和緯度來自navigator.geolocation物體。這是我的安裝腳本的一部分:Vue.component('catalog', require('./components/Catalog'));Vue.component('address-autocomplete', require('./components/AddressAutoComplete'));window.googleMapsClient = require('@google/maps').createClient({ key: "MY_API_KEY"});還有我的Vue組件:getLocationFromGeoData() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition( this.setLocation, this.showError ); } else { showLocationError("Geolocation wird nicht unterstützt!"); }},setLocation(position) { var self = this; this.location.latitude = position.coords.latitude; this.location.longitude = position.coords.longitude; var latLng = { lat: parseFloat(this.location.latitude), lng: parseFloat(this.location.longitude) }; googleMapsClient.geocode({'location': latLng}).asPromise() .then((response) => { self.location.address = results[1].formatted_address; }).catch((err) => { showLocationError(err); });},
Google Maps Geocode意外的屬性位置
慕婉清6462132
2021-05-06 19:59:40