如果Google Places API是返回数组

时间:2017-09-13 18:25:53

标签: javascript angular api google-places-api google-places

如果地址如此回复"#301,1833 N 105th St,Shoreline,WA 98133,USA",那么Apt编号#301,不作为子预测。当地址是" 1918 8th Ave#3200,Seattle WA,89101,USA" #3200被视为Apt。

两种情况都会带回整个地址,但是当Google第一个值时,Google无法识别它们。我正在使用Gin Angular和JavaScript,所以这些技术中的任何建议都会很棒。

for (i=0; i < place.address_components.length; i++) {
                        comp = place.address_components[i];
                        // State
                        if (!location.details.State && comp.types.indexOf('administrative_area_level_1') !== -1) {
                            location.details.State = comp.short_name;
                        }
                        // City
                        else if (!location.details.City && comp.types.indexOf('locality') !== -1) {
                            location.details.City = comp.long_name;
                        }
                        // Zip
                        else if (!location.details.Zip && comp.types.indexOf('postal_code') !== -1) {
                            location.details.Zip = comp.long_name;
                        }
                        // Street Name
                        else if (!location.details.Street.Name && comp.types.indexOf('route') !== -1) {
                            location.details.Street.Name = comp.long_name;
                        }
                        // Street Number
                        else if (!location.details.Street.Number && comp.types.indexOf('street_number') !== -1) {
                            location.details.Street.Number = comp.long_name;
                        }
                        // Apt
                        else if (!location.details.Apt && comp.types.indexOf('subpremise') !== -1) {
                            location.details.Apt = comp.long_name;
                        }
                    }
                    location.details.Street = (location.details.Street.Number + ' ' +location.details.Street.Name).trim();
                    if (!location.details.Street) {
                        location.details.Street = location.formatted_address_line1;
                    }
}

0 个答案:

没有答案