获取我所在位置附近的panoramio.com照片

时间:2011-07-03 18:19:41

标签: java android gps latitude-longitude

我正试图从http://panoramio.com到我所在地附近拍照。 它的工作如果纬度和经度是积极的,但如果其中一个是负的panoramio不给我任何结果。 任何想法代码有什么问题?

String getPanoramioUrl(double minx, double maxx, double miny, double maxy){
    //set=full or = public?
    return "http://www.panoramio.com" +
            "/map/get_panoramas.php?" +
            "set=public&from=0&to=100&minx="+minx+"&miny="+miny+"&maxx="+maxx+"&maxy="+maxy;
}

            lat = loc.getLatitude();
            lon = loc.getLongitude();

            //lat = -74.005973;
            //lon = 40.714353;

            double diff = 0.002;
            JSONObject json;
            int retries = 0;
            while (true){
                if (retries > 10){
                    Log.d(TAG, "giving up after 10 retries to get photo");
                    return;
                }

                String url = getPanoramioUrl(
                        lon>0 ? lon-diff : lon+diff,
                        lon>0 ? lon+diff : lon-diff,
                        lat>0 ? lat-diff : lat+diff,
                        lat>0 ? lat+diff : lat-diff);
                Log.d(TAG, "getting url: " + url);
                json = getJSONfromURL(url);
                int count;
                Log.d(TAG, "got response: " + json.toString());
                try{
                    count = json.getJSONArray("photos").length();
                }catch(JSONException exc){
                    Log.d(TAG, exc.toString());
                    return;
                }
                if (count > 0){
                    break;
                }
                diff = diff*3;
                retries++;
            }

1 个答案:

答案 0 :(得分:0)

差异总是正面的,所以 String url = getPanoramioUrl(lon-diff,lon + diff,lat-diff,lat + diff);