嗨我想保留从json数据到地址名称
的经度和经度的地理编码 getAllMap() {
this.mapLocationService.getAll()
.subscribe(
ml => {
this.maplocations = ml;
let latlng = new google.maps.LatLng(this.maplocations['map_location_latitude'], this.maplocations['map_location_longitude']); // <- problem when i call init google map
console.log(latlng);
let request = latlng;
let geocoder = new google.maps.Geocoder();
geocoder.geocode(request, (results, status) => {
if (status === google.maps.GeocoderStatus.OK) {
console.log('status' + status);
if (results[0] != null) {
this.city = results[0].address_components[results[0].address_components.length - 4].short_name;
console.log('city' + this.city);
} else {
this.city = 'No address available';
}
}
});
},
error => {
this.errorMessage = error;
}
);
}
import { } from '@types/googlemaps';
declare var google: any;
所以问题总是显示错误
ERROR ReferenceError:未定义谷歌
答案 0 :(得分:0)
尝试使用
import { } from 'googlemaps';
而不是
import { } from '@types/googlemaps';
declare var google: any;