如何使用纬度、经度和半径(距离)将区域划分为较小的区域,在Java的Google place Search API中



我使用Java中的谷歌雷达位置搜索API。我使用特定地区的纬度、经度和半径(距离)提出请求。我收到了大约200个回复(API的最大回复)。如果我得到200个回复,我必须使用纬度和经度将我的请求分成更小的大小,这样我就可以覆盖整个圆圈区域,以获得该区域所有地方的详细信息。那么,如何使用纬度、经度和半径来划分圆形区域呢?只有这样,我才能到达那个地区的每一个地方。请帮帮我。

这是代码,

方法调用API,我给出了我的纬度、经度、类型=餐厅、半径=20000(找出20公里内该地区的餐厅)

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();
      }
}

从上面的代码中,在迭代之后,我最多得到200个响应。此API最多只能提供200个结果,因为它被限制为200个。如果我得到200个结果,那么就不会有更多的回复了。我需要把这个地区分成更多的小地区,这样我就可以在这个地区找到更多的餐馆。

您可以使用minPriceLevel and maxPriceLevel将搜索拆分为四个结果,即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;

最新更新