简体   繁体   English

Google Places api搜索的首次匹配

[英]First match from google places api search

is there a way to get only the first match when applying google places api with text search? 在文本搜索中应用Google Places API时,有没有办法只获得第一个匹配项?

For ex. 对于前。 the url below gives more than 1 matches... 以下网址给出了超过1个匹配项...

https://maps.googleapis.com/maps/api/place/textsearch/xml?query=Leipzig+Germany+Univ+Leipzig&sensor=false&key=KEY

Can I add a parameter in order to take the first match? 我可以添加参数以进行第一个匹配吗?

No, you cannot limit the results included in the result set. 不可以,您不能限制结果集中包含的结果。 You can get the first match simply by getting the first result in the result set. 您可以简单地通过获得结果集中的第一个结果来获得第一个匹配项。 I'll include some Java code since you didn't specify what language you are using. 我将包含一些Java代码,因为您没有指定使用的语言。

JSONObject json = new JSONObject(responseStr);
JSONArray results = json.getJSONArray("results");
JSONObject firstResult = results.getJSONObject(0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM