0
var city, country;
geocoder.geocode(
{'address': city + ', ' + country}, function(results, status) {}
);
的問題是當VAR city
是錯誤的,是隨機streetname(隨機城市) 他把這個在結果中的位置,但我只希望城市...
有沒有辦法只能用geocode()
搜索一個城市?
var city, country;
geocoder.geocode(
{'address': city + ', ' + country}, function(results, status) {}
);
的問題是當VAR city
是錯誤的,是隨機streetname(隨機城市) 他把這個在結果中的位置,但我只希望城市...
有沒有辦法只能用geocode()
搜索一個城市?
//get address info such as city and state from lat and long
geocoder.geocode({'latLng': latlng}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
//break down the three dimensional array into simpler arrays
for (i = 0 ; i < results.length ; ++i)
{
var super_var1 = results[i].address_components;
for (j = 0 ; j < super_var1.length ; ++j)
{
var super_var2 = super_var1[j].types;
for (k = 0 ; k < super_var2.length ; ++k)
{
//find city
if (super_var2[k] == "locality")
{
//put the city name in the form
main_form.city.value = super_var1[j].long_name;
}
//find county
if (super_var2[k] == "administrative_area_level_2")
{
//put the county name in the form
main_form.county.value = super_var1[j].long_name;
}
//find State
if (super_var2[k] == "administrative_area_level_1")
{
//put the state abbreviation in the form
main_form.state.value = super_var1[j].short_name;
}
}
}
}
}
我有一個輸入字符串(= var city)en我必須找到那個城市。 但是如果有人在輸入字段中放置一條街道,那應該沒有結果,但我不能去檢查字符串是街道還是城市... 但是,如果我檢查這個: if(city == super_var1 [j] .long_name){ do stuff; } 那應該做檢查,不是? – user3745218
你從哪裏得到var city? –
它似乎應該解決錯誤輸入的問題。代碼示例不會向我們顯示定義值的位置。 – dmullings