Reputation: 175
I am using google radar place search API in Java. I am giving request using latitude,longitude and radius (distance) of particular region. I am getting about 200 responses (Maximum by this API). If I get 200 responses, I have to divide my request into smaller sizes using latitude and longitude, so that I can cover the full region of the circle to get details about all the places in that region. So, how to divide the Circular region using latitude, longitude and radius? So only, I can get each and every places in that region. Please, help me out.
Here is the code,
Method to invoke the API, I gave my latitude, longitude, type= restaurant, radius = 20000 (to find out the restaurants in that region within 20 kms)
public void performGooglePlaceSearch(double lati,double lang,int rad,String type,String key)
{
try{
String placeSearchURL="https://maps.googleapis.com/maps/api/place/radarsearch/json?location="+lati+","+lang+"&radius="+rad+"&types="+type+"&key="+key;
Client placeSearchClient = Client.create();
WebResource placeSearchWebResource = placeSearchClient.resource(placeSearchURL);
ClientResponse placeSearchClientResponse = placeSearchWebResource.accept("application/json").get(ClientResponse.class); //Here I will receive the json response.
String placeSearchOutput = placeSearchClientResponse.getEntity(String.class);
System.out.println(placeSearchOutput);
//To convert to Java object, I use this classes. Because, I need to convert from Json response to Java object.
ObjectMapper placeSearchMapper = new ObjectMapper();
// I created java classes in PlaceSearchResponse class for all the json responses I received, ie, latitude, longitude, id, place_id,
PlaceSearchResponse placeSearchResponse=placeSearchMapper.readValue(new URL(placeSearchURL), PlaceSearchResponse.class);
//Iterating all the Java objects ie, latitude, longitude, id, place_id
Iterator iter=(Iterator) placeSearchResponse.getResults().iterator();
while(iter.hasNext())
{
PlacesInfo placeDetails=(PlacesInfo) iter.next();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
From this above code, after iterating, I get maximum of 200 responses. This API gives maximum of 200 results only, because, it is limited to 200. If I get 200 results, then there will more no of responses be available. I need to break this region into more small regions, so that I can get more no of restaurants available in this region.
Upvotes: 0
Views: 844
Reputation: 7228
You can use minPriceLevel and maxPriceLevel
to split search into four results ie 0-1,1-2,2-3,3-4
String placeSearchURL="https://maps.googleapis.com/maps/api/place/radarsearch/json?location="+lati+","+lang+"&radius="+rad+"&types="+type+"&minprice="+min"+"&maxprice="+max"+ &key="+key;
Upvotes: 0