这是我用来处理这个问题的案例陈述。它有效,但不确定它是否是最优雅的解决方案。
Dim street As String = ""
Dim city As String = ""
Dim state As String = ""
Dim country As String = ""
Dim zip As String = ""
Dim phone As String = ""
Dim website As String = ""
' No guareentee to the order of even if the data will be there so we check each type. '
For j = 0 To array.result.address_components.Length - 1
Select Case array.result.address_components(j).types(0)
Case "street_number"
street += array.result.address_components(j).long_name()
Case "route"
street += " " & array.result.address_components(j).long_name()
Case "locality"
city = array.result.address_components(j).long_name()
Case "administrative_area_level_1"
state = array.result.address_components(j).long_name()
Case "country"
country = array.result.address_components(j).long_name()
Case "postal_code"
zip = array.result.address_components(j).long_name()
End Select
Next
我基本上循环浏览 address_components 并检查它们的类型值。如果该值是我正在寻找的值,我会分配它。如果没有街道号码,我稍后会在街道上调用 Trim() 以删除我添加的空白区域。