我正在尝试使用Google places API,但在我的一些请求中收到以下错误消息:
无效的请求。其中一个输入参数包含非UTF-8字符串。
例如,以下请求-https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=WRAFTON%HOUSE%SURGERY%WRAFTON%HOUSE%SURGERY%9%WELLFIELD%ROAD%HATFIELD%HERTFORDSHIRE%AL10 S
{
"candidates" : [],
"error_message" : "Invalid request. One of the input parameters contains a non-UTF-8 string.",
"status" : "INVALID_REQUEST"
}
但如果我去掉这些数字,比如-https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=WRAFTON%HOUSE%SURGERY%WRAFTON%HOUSE%SURGERY%WELLFIELD%ROAD%HATFIELD%HERTFORDSHIRE%
{
"candidates" : [
{
"formatted_address" : "9-11 Wellfield Rd, Hatfield AL10 0BS, United Kingdom",
"geometry" : {
"location" : {
"lat" : 51.7659979,
"lng" : -0.2269138
},
"viewport" : {
"northeast" : {
"lat" : 51.76722407989272,
"lng" : -0.2257391701072778
},
"southwest" : {
"lat" : 51.76452442010727,
"lng" : -0.2284388298927222
}
}
},
"name" : "Wrafton House Surgery NHS",
"photos" : [
{
"height" : 2448,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/101621497138346721555/photos\"\u003eGicu Razoare\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAABVxpTtU1jnkajKeMys5GsNFha4PMisyTPaw4nyhpQMH0hwOu2kDDnGhKWXpsfiXqmBAGyO5ctA86dbtavh0xWZEspctQXo1EAcJswgxdnl0zSzG5b2xMbzSK6P6lRv2QEhCIPKzSjVUEQBSM3xutYsrwGhTGcax2XoglbtUgKsRFSIJF2oaQwA",
"width" : 3264
}
],
"place_id" : "ChIJ85ML6oI8dkgRKziTLkoRGeA",
"rating" : 1.9,
"types" : [ "hospital", "point_of_interest", "establishment" ]
}
],
"status" : "OK"
}
这是因为数字吗?有没有一种方法,我可以绕过这一点,不删除他们?
导致此错误的是"9"和"AL10S"中的"%"字符。您需要正确编码URL。
试试这个:https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=Wrafton外科,赫特福德郡哈特菲尔德威尔菲尔德路9-11号,AL10 0BS
希望这有帮助!