I'm using unfolding library for processing to retrieve some lodging infos from google map. I set the program searching and displaying the data in 20km of the specific spot on the map. But it has a problem. I extended the restrict area widely however the app can't get the results over 20. It loaded the googlemap api JSON by URL. I know that the search scope is limited by the radius value of URL.
the code is below
//skip the lib loads
UnfoldingMap map;
DebugDisplay debugDisplay;
SimplePointMarker studio527;
String url;
JSONObject json;
JSONArray resultData;
ArrayList 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);
//map.addMarkers(studio527); // if you want to creat your own mark style.
//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 lodgings
String hotel = result.getString("name");
JSONObject geometry = result.getJSONObject("geometry");
// location of lodgings
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);
font = createFont("NanumBarunpen",15);
textFont(font);
textAlign(LEFT);
}
}
void draw() { int count = 0; background(255); //map.draw();
for(int i =0; i<infos.size(); i++){
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);
text(name, pos.x, pos.y);
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; } }