Google Place API附近搜索多类型参数传递失败的技术咨询
Hey there! I’ve run into this exact issue before, so let me break it down for you:
The Nearby Search endpoint of the Google Places API does not support multiple values for the types parameter — that’s why both types=atm|restaurant and types=atm,restaurant aren’t working for you. This is an intentional limitation of the endpoint; it only accepts a single type value at a time.
Workarounds to get results for multiple types:
Use the
keywordparameter instead: You can combine your desired types as keywords, which the API will use to match relevant places. For example:https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=30.642550,76.817336&key=examplekey&sensor=false&radius=200&keyword=atm,restaurantYou can also use space-separated keywords like
keyword="atm restaurant"for broader matching.Make separate requests for each type: If you need precise results for each type, send one Nearby Search request for
types=atmand another fortypes=restaurant, then merge the results on your client side. Just keep in mind that each request counts against your API quota.Switch to the Place Text Search endpoint: This endpoint does support multiple types using the
|separator. The tradeoff is that Text Search is more focused on text-based matching rather than strict proximity, but it can work for your use case. Example request:https://maps.googleapis.com/maps/api/place/textsearch/json?query=near+30.642550,76.817336&key=examplekey&radius=200&types=atm|restaurant
Hope one of these solutions works for you!
内容的提问来源于stack exchange,提问作者user1001176

