您好,当用户在地图中输入城市时,我正在尝试获取地震信息。现在我通过硬编码制作边界框(geonames 地震 api 需要)。我想将边界框设为输入城市的大小。我在 geocoder api v3 中看到这样做:
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
map.fitBounds(results[0].geometry.viewport);
}
});
问题 - 这不会让我得到 geonames 需要的东北西南。有人知道怎么做吗?
我当前的代码
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
// Calculate bounding box based on the given address
var north = results[0].geometry.location.lat() + .5;
var south = results[0].geometry.location.lat() - .5;
var east = results[0].geometry.location.lng() + .5;
var west = results[0].geometry.location.lng() - .5;
var earthquake = 'http://api.geonames.org/earthquakesJSON?north=' + north + '&south=' + south + '&east=' + east + '&west=' + west + '&username=*****';
+5 -5 是扩展坐标中的数字以创建南北......等