Google maps 带地址的Google geocode返回一个结果
将现有地址作为参数的地理编码器结果仅返回街道地址。为什么?地址是有效的。它已经在美国进行了测试 我的电话:Google maps 带地址的Google geocode返回一个结果,google-maps,google-geocoder,Google Maps,Google Geocoder,将现有地址作为参数的地理编码器结果仅返回街道地址。为什么?地址是有效的。它已经在美国进行了测试 我的电话: checkAddress(street, strNo, post_code, area, function (results) { if (results) { $.each(results, function (i, address) { if (address.types[0] == "street_address") { it
checkAddress(street, strNo, post_code, area, function (results) {
if (results) {
$.each(results, function (i, address) {
if (address.types[0] == "street_address") {
itemStreetNo = address.address_components[0].long_name;
itemStreet = address.address_components[1].long_name;
}
if (address.types[0] == "route") {
itemStreet = address.address_components[0].long_name;
}
if (address.types[0] == "postal_code") {
itemPostalCode = address.address_components[0].long_name;
}
if (address.types[0] == "country") {
itemCountry = address.address_components[0].long_name;
}
if (address.types[0] == "locality") {
itemRegion = address.address_components[0].long_name;
}
}
});
我的职能是:
function checkAddress(address, number, zipcode, area, callback) {
var geocoder = new google.maps.Geocoder;
var addr = address + ' ' + number + ' ' + zipcode + ' ' + area;
geocoder.geocode({ 'address': addr }, function (results, status) {
if (status === google.maps.GeocoderStatus.OK) {
if (results[0]) {
callback(results);
}
else {
callback(null);
}
}
else {
callback(null);
}
});
}
您只搜索1个组件(
address.address\u components[0]
),因此只会得到1个结果
地址。地址\u组件[0]
包含一个组件,例如“路由”。然后address.address\u components[1]
包含另一个组件,例如“locality”,然后address.address\u components[2]
。。。据我记忆所及,部件的顺序是随机的
所以你需要的是迭代。对于检查类型的每个组件,这让您知道值应该放在哪里
我为一个不同的堆栈溢出问题编写了一个函数,这个函数执行这个迭代,对任何组件进行“钓鱼”
看看它是否适合你;让我知道
您只搜索1个组件(
地址。地址\u组件[0]
),因此您只得到1个结果
地址。地址\u组件[0]
包含一个组件,例如“路由”。然后address.address\u components[1]
包含另一个组件,例如“locality”,然后address.address\u components[2]
。。。据我记忆所及,部件的顺序是随机的
所以你需要的是迭代。对于检查类型的每个组件,这让您知道值应该放在哪里
我为一个不同的堆栈溢出问题编写了一个函数,这个函数执行这个迭代,对任何组件进行“钓鱼”
看看它是否适合你;让我知道
谢谢您的代码。这就是我需要得到的所有信息。谢谢你的代码。这就是我获得所有信息所需要的。