开源项目之Android Panoramio

简介

Panoramio 是 Android 手机平台上的一个应用程序将告诉您附近的照片和兴趣点。项目如图:


效果如图(google地图没出来):




分析

public class BitmapUtils {//从一个URL加载位图
public class ImageAdapter extends BaseAdapter {	//适配器显示分享的照片
public class ViewMap extends MapActivity { // 显示自定义地图
public class ViewImage extends Activity { // 单个图片展示
public class PanoramioItem implements Parcelable { //服务器返回数据封装
public class Panoramio extends MapActivity implements OnClickListener {	//用户选择搜索区域
public class ImageManager {	//管理 负责下载和解析的搜索结果 关键操作如下:
	public void run() {	//线程获取数据

			String url = THUMBNAIL_URL;
			url = String.format(url, mMinLat, mMinLong, mMaxLat, mMaxLong);
			try {
				URI uri = new URI("http", url, null);
				HttpGet get = new HttpGet(uri);

				HttpClient client = new DefaultHttpClient();
				HttpResponse response = client.execute(get);
				HttpEntity entity = response.getEntity();
				String str = convertStreamToString(entity.getContent());
				JSONObject json = new JSONObject(str);
				parse(json);
			} catch (Exception e) {
				Log.e(TAG, e.toString());
			}
		}
		private void parse(JSONObject json) {	//分析数据
			try {
				JSONArray array = json.getJSONArray("photos");
				int count = array.length();
				for (int i = 0; i < count; i++) {
					JSONObject obj = array.getJSONObject(i);
					long id = obj.getLong("photo_id");
					String title = obj.getString("photo_title");
					String owner = obj.getString("owner_name");
					String thumb = obj.getString("photo_file_url");
					String ownerUrl = obj.getString("owner_url");
					String photoUrl = obj.getString("photo_url");
					double latitude = obj.getDouble("latitude");
					double longitude = obj.getDouble("longitude");
					Bitmap b = BitmapUtils.loadBitmap(thumb);
					if (title == null) {
						title = mContext.getString(R.string.untitled);
					}

					final PanoramioItem item = new PanoramioItem(id, thumb, b,
							(int) (latitude * Panoramio.MILLION),
							(int) (longitude * Panoramio.MILLION), title,
							owner, ownerUrl, photoUrl);
					final boolean done = i == count - 1;
					mHandler.post(new Runnable() {
						public void run() {

							sInstance.mLoading = !done;
							sInstance.add(item);
						}
					});
				}
			} catch (JSONException e) {
				Log.e(TAG, e.toString());
			}
		}
		private String convertStreamToString(InputStream is) {	//转换
			BufferedReader reader = new BufferedReader(
					new InputStreamReader(is), 8 * 1024);
			StringBuilder sb = new StringBuilder();

			String line = null;
			try {
				while ((line = reader.readLine()) != null) {
					sb.append(line + "\n");
				}
			} catch (IOException e) {
				e.printStackTrace();
			} finally {
				try {
					is.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}

			return sb.toString();
		}

下载

项目下载!


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值