Setting searching scope problem _ google map api

edited August 2017 in Library Questions

I'm using unfolding library for processing to retrieve some lodging infos from google map. I made the program search and display the data in 20km of the specific spot on the map. But it has some problem. I extended the restrict area widely but the app can't get the results over 20. It load the google map api JSON by URL. I learn that the search scope is bounded by the radius value of URL. Is there any limitation to get the number of results from the google map? The another problem is that the app sometime can't display the background google map image. I guess that it might be related to the google api key or changed WI-FI environment.

url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=37.705160,127.447744&radius=20000&type=lodging&key=MYKEY";

the code is below

        UnfoldingMap map;
        DebugDisplay debugDisplay;
        SimplePointMarker studio527;

        String url;
        JSONObject json;
        JSONArray resultData;
        ArrayList<Result> infos;
        PFont font;

        // the coordination of 527 Studio
        float loc_lati = 37.705160;
        float loc_longi = 127.447744;


        void setup() {
                size(800, 600);
                background(255);
                Location artLocation = new Location(37.705160 , 127.447744); // the spot
                studio527 = new SimplePointMarker(artLocation);

                map = new UnfoldingMap(this, new Google.GoogleMapProvider()); // map style
                MapUtils.createDefaultEventDispatcher(this, map);
                map.zoomAndPanTo(artLocation, 17); // How much closer to the spot
                float maxPanningDistance = 20; // in km
                map.setPanningRestriction(artLocation, maxPanningDistance);

                //Create debug display 
                //debugDisplay = new DebugDisplay(this, map);

                //load JSON
                url = "https://" + "maps.googleapis.com/maps/api/place/nearbysearch/json?location=37.705160,127.447744&radius=2000&type=lodging&key=MYKEY"; // distance unit meter
                json = loadJSONObject(url);
                resultData = json.getJSONArray("results");
                println(" the number of hotel : " + resultData.size());

                infos = new ArrayList<Result>();

                for(int i=0; i<resultData.size(); i++){
                  JSONObject result = resultData.getJSONObject(i);

                  // name of hotel
                  String hotel = result.getString("name");
                  JSONObject geometry = result.getJSONObject("geometry");

                  // location of hotel
                  JSONObject location = geometry.getJSONObject("location"); //no coordination
                  float lat = location.getFloat("lat");
                  float lng = location.getFloat("lng");  
                  println( " coordination : latitude - " + lat + " , longitude - " + lng );
                  Location loc = new Location(lat, lng);
                  Result info = new Result(hotel, loc);
                  infos.add(info);

                  /*// create  markers
                  markers[i] = new SimplePointMarker(loc);
                  map.addMarkers(markers[i]);
                  */

                  font = createFont("NanumBarunpen",15);
                  textFont(font);
                  textAlign(LEFT);
                }

        }

        void draw() {
            int count = 0;
            background(255);
            //map.draw();
            //debugDisplay.draw();

            for(int i =0; i<infos.size(); i++){ 

               //ScreenPosition pos = markers[i].getScreenPosition(map);
               Result info = infos.get(i);

               String name = info.getHotel();
               Location coordination = info.getLocation();
               ScreenPosition pos = info.getPos();

               strokeWeight(16);
               stroke(67, 211, 227, 100);
               noFill();
               ellipse(pos.x, pos.y, 12, 12);

               fill(0);
               //textSize(13);
               text(name, pos.x, pos.y);
               //text("lng : " + coordination.x, pos.x, pos.y+23);
               //text("lat : " + coordination.y, pos.x +120, pos.y+23);
               println(" count : " + count++ );

            }
            println("done");

            ScreenPosition  studioPos = studio527.getScreenPosition(map);
            strokeWeight(12);
            stroke(200, 0, 0, 200);
            strokeCap(SQUARE);
            noFill();
            float s = 44;
            arc(studioPos.x, studioPos.y, s, s, -PI * 0.9, -PI * 0.1);
            arc(studioPos.x, studioPos.y, s, s, PI * 0.1, PI * 0.9);
            fill(0);
            text("527Studio", studioPos.x - textWidth("527 Studio") / 2, studioPos.y + 4);
        }


        class Result{
          String hotel;
          Location loc;
          SimplePointMarker marker;

          Result(String _name, Location _loc){
            hotel = _name;
            loc = _loc;
          }
          String getHotel(){
            return hotel;
          } 

          Location getLocation(){
            return loc;
          }

          ScreenPosition getPos(){
            marker = new SimplePointMarker(loc);
            map.addMarkers(marker);
            ScreenPosition pos = marker.getScreenPosition(map);
            return pos;
          }
        }

Answers

Sign In or Register to comment.