Javascript 为什么latitude results对象与google maps api不同?
我在路过这样一个城市时,碰到了谷歌地图api:Javascript 为什么latitude results对象与google maps api不同?,javascript,google-maps,geolocation,geocoding,Javascript,Google Maps,Geolocation,Geocoding,我在路过这样一个城市时,碰到了谷歌地图api: this.geoCode = function(city) { var dfd = $q.defer(); var geocoder = new google.maps.Geocoder(); geocoder.geocode({'address': city}, function (results, status) { console.log(
this.geoCode = function(city) {
var dfd = $q.defer();
var geocoder = new google.maps.Geocoder();
geocoder.geocode({'address': city},
function (results, status) {
console.log('map response: ', results);
cityObj.address = results[0].formatted_address;
getWeather(results[0].geometry.bounds.R.R, results[0].geometry.bounds.j.j)
.then(function(response) {
cityObj = response;
dfd.resolve(cityObj);
});
});
return dfd.promise;
};
就在两周前,我通过以下方式从results对象访问纬度/经度:
getWeather(results[0].geometry.bounds.R.R, results[0].geometry.bounds.j.j)
现在,结果对象如下所示:
getWeather(results[0].geometry.bounds.H.H, results[0].geometry.bounds.j.j)
如您所见,纬度从R.R对象上的访问变为H.H对象上的访问。我不知道谷歌地图是否经常这样做。如果是,如何使用代码不断解析数据以获得纬度/经度,而不不断更改对象字母?如有任何反馈,将不胜感激。感谢这是因为它被缩小了,属性名称并不总是相同的,也不意味着可以直接访问 这是一个很好的例子。因此,您可以使用
getCenter()
等方法获取对象,然后获取纬度和经度值
var center = results[0].geometry.bounds.getCenter();
var lat = center.lat();
var lng = center.lng();
或者您也可以使用
几何体。位置
因为它已经是一个可用的LatLng
实例,这一切都取决于您需要检索的坐标。您可以使用它访问lat,lng,这对我来说很好。var latitude=results[0]。geometry.location.lat();var longitude=results[0]。geometry.location.lng();复制品的复制品的复制品的复制品