简体   繁体   中英

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?

For ex. the url below gives more than 1 matches...

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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