如果我这样做: http://maps.googleapis.com/maps/api/geocode/json?address=kemayoran&sensor=false这是我想要的结果,如果不是因为我希望在访问者键入kem而不是kemayoran时这样做。
{
"results" : [
{
"address_components" : [
{
"long_name" : "Kemayoran",
"short_name" : "Kemayoran",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Jakarta Pusat",
"short_name" : "Jakarta Pusat",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Jakarta",
"short_name" : "Jakarta",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Jakarta Capital Region",
"short_name" : "Jakarta Capital Region",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Indonesia",
"short_name" : "ID",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Kemayoran, Jakarta, Indonesia",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : -6.14935190,
"lng" : 106.8857620
},
"southwest" : {
"lat" : -6.171493900000001,
"lng" : 106.84546290
}
},
"location" : {
"lat" : -6.16165420,
"lng" : 106.8550150
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : -6.14935190,
"lng" : 106.8857620
},
"southwest" : {
"lat" : -6.171493900000001,
"lng" : 106.84546290
}
}
},
"types" : [ "sublocality", "political" ]
},
{
"address_components" : [
{
"long_name" : "Kemayoran",
"short_name" : "Kemayoran",
"types" : [ "train_station", "transit_station", "establishment" ]
},
{
"long_name" : "Jalan Garuda",
"short_name" : "Jalan Garuda",
"types" : [ "route" ]
},
{
"long_name" : "Pasar Baru",
"short_name" : "Pasar Baru",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Sawah Besar",
"short_name" : "Sawah Besar",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Jakarta Pusat",
"short_name" : "Jakarta Pusat",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Jakarta",
"short_name" : "Jakarta",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Jakarta Capital Region",
"short_name" : "Jakarta Capital Region",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Indonesia",
"short_name" : "ID",
"types" : [ "country", "political" ]
},
{
"long_name" : "10710",
"short_name" : "10710",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Kemayoran, Jalan Garuda, Jakarta 10710, Indonesia",
"geometry" : {
"location" : {
"lat" : -6.16204140,
"lng" : 106.84154990
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : -6.160692419708497,
"lng" : 106.8428988802915
},
"southwest" : {
"lat" : -6.163390380291502,
"lng" : 106.8402009197085
}
}
},
"types" : [ "train_station", "transit_station", "establishment" ]
},
{
"address_components" : [
{
"long_name" : "Kemayoran",
"short_name" : "Kemayoran",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Kemayoran",
"short_name" : "Kemayoran",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Jakarta Pusat",
"short_name" : "Jakarta Pusat",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Jakarta",
"short_name" : "Jakarta",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Jakarta Capital Region",
"short_name" : "Jakarta Capital Region",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Indonesia",
"short_name" : "ID",
"types" : [ "country", "political" ]
},
{
"long_name" : "10620",
"short_name" : "10620",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Kemayoran, Jakarta 10620, Indonesia",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : -6.1602730,
"lng" : 106.8572680
},
"southwest" : {
"lat" : -6.1664210,
"lng" : 106.851820
}
},
"location" : {
"lat" : -6.16165420,
"lng" : 106.8550150
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : -6.1602730,
"lng" : 106.8572680
},
"southwest" : {
"lat" : -6.1664210,
"lng" : 106.851820
}
}
},
"types" : [ "sublocality", "political" ]
},
{
"address_components" : [
{
"long_name" : "Kemayoran",
"short_name" : "Kemayoran",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Krembangan",
"short_name" : "Krembangan",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Surabaya",
"short_name" : "Surabaya",
"types" : [ "locality", "political" ]
},
{
"long_name" : "East Java",
"short_name" : "East Java",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Indonesia",
"short_name" : "ID",
"types" : [ "country", "political" ]
},
{
"long_name" : "60176",
"short_name" : "60176",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Kemayoran, Surabaya 60176, Indonesia",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : -7.2369960,
"lng" : 112.7333040
},
"southwest" : {
"lat" : -7.2465120,
"lng" : 112.726760
}
},
"location" : {
"lat" : -7.2417540,
"lng" : 112.7300320
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : -7.2369960,
"lng" : 112.7333040
},
"southwest" : {
"lat" : -7.2465120,
"lng" : 112.726760
}
}
},
"types" : [ "sublocality", "political" ]
},
{
"address_components" : [
{
"long_name" : "Kemayoran",
"short_name" : "Kemayoran",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "Bangkalan",
"short_name" : "Bangkalan",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Bangkalan Regency",
"short_name" : "Bangkalan Regency",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "East Java",
"short_name" : "East Java",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Indonesia",
"short_name" : "ID",
"types" : [ "country", "political" ]
},
{
"long_name" : "69116",
"short_name" : "69116",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Kemayoran, Bangkalan 69116, Indonesia",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : -7.0243290,
"lng" : 112.7483040
},
"southwest" : {
"lat" : -7.039670,
"lng" : 112.7349340
}
},
"location" : {
"lat" : -7.031263999999999,
"lng" : 112.7417250
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : -7.0243290,
"lng" : 112.7483040
},
"southwest" : {
"lat" : -7.039670,
"lng" : 112.7349340
}
}
},
"types" : [ "sublocality", "political" ]
}
],
"status" : "OK"
}
我有几个kemayoran。
如果我这样做:
http://maps.googleapis.com/maps/api/geocode/json?address=kemayoran&sensor=false&bounds=-6,106|-5,107
我得到了kemayoran。但只有一个,即使所有其他的kemayoran都在范围内。
我在第一个查询中正确指定了绑定,因为你们都可以看到,kemayoran的纬度逻辑正好在-6,106 | -5,107
的范围内如果我这样做
http://maps.googleapis.com/maps/api/geocode/json?address=kemay&sensor=false&bounds=-6,106|-5,107
我得到了Kemnay而不是kemayoran。
将此与此私有API进行比较: http://maps.google.com/maps/suggest?q=kemay&cp=2&hl=en&gl=&v=2&clid=1&json=a&ll=-6.230664,106.55365&spn=1,1&src=1&num=20&numps=0
结果正是我想要的,除了它没有给出经度和经度,更不用说是私有API了。
那么,我该怎么办?
答案 0 :(得分:2)
界限只是偏向搜索结果的一种方式,如Google's documentation of the webservice中所述。由于您指定了搜索字符串“Kemay”,因此它会在苏格兰找到完全匹配。但是,正如您输入确切字符串时所观察到的那样,它会找到您要查找的内容。
修改强>
这听起来好像您正在寻找像地方自动填充功能(via webservice或更好的javascript library)这样的功能。在键入部分字符串时,这似乎可以提供更准确的结果。