android:获得poi图片的一种方法(百度地图api)

    xiaoxiao2021-12-10  28

    摘自:http://blog.csdn.net/z914022466/article/details/47728469

    百度地图api中关于poi检索的内容实际上是比较少的。

    如果想做poi的介绍界面,需要 poi的图片。。。但是百度地图api中只提供了poi的url。没办法,用正则表达式自己搞!

    一开始遇到的问题是无法解析getDetailUrl()的源码,后来发现这个url是个废弃的有么有搞错

    自己构建如下"http://map.baidu.com/detail?qt=ninf&uid="+uid.get(i)+"&detail="+type.get(i)"

    对于cater类型的网页,获取图片的正则表达式为

    [java]  view plain  copy "(?<=<img src=\").*(?=\" class=\"head-img\"/>)"  

    关键源码如下:

    [java]  view plain  copy public class webContent {       public  byte[] readStream(InputStream inputStream) throws Exception {           byte[] buffer = new byte[1024];           int len = -1;           ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();              while ((len = inputStream.read(buffer)) != -1) {           byteArrayOutputStream.write(buffer, 0, len);           }              inputStream.close();           byteArrayOutputStream.close();           return byteArrayOutputStream.toByteArray();           }              public  String testGetHtml(String urlpath) throws Exception {           URL url = new URL(urlpath);           HttpURLConnection conn = (HttpURLConnection) url.openConnection();           conn.setConnectTimeout(6 * 1000);          //   StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build());   //        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects().detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());           conn.setRequestMethod("GET");              if (conn.getResponseCode() == 200) {           InputStream inputStream = conn.getInputStream();           byte[] data = readStream(inputStream);           Log.e("字节数组长度", data.length+"个字节");           String html = new String(data);           return html;           }           return null;           }           public String getTitle(String s) {               String regex;               String title = "";               ArrayList<String> list = new ArrayList<String>();               regex = "(?<=<img src=\").*(?=\" class=\"head-img\"/>)";               Pattern pa = Pattern.compile(regex);               Matcher ma = pa.matcher(s);               while (ma.find()) {                   list.add(ma.group());               }               for (int i = 0; i < list.size(); i++) {                   title = title + list.get(i);               }               return (title);           }   public ImageLoader loadImage(String  url,Context context){           RequestQueue requestQueue = Volley.newRequestQueue(context);           final LruCache<String, Bitmap> lruCache = new LruCache<String, Bitmap>(50);           ImageCache imageCache = new ImageCache() {                              @Override   <span style="white-space:pre">        </span>public void putBitmap(String key, Bitmap value) {   <span style="white-space:pre">        </span>lruCache.put(key, value);   <span style="white-space:pre">        </span>}      <span style="white-space:pre">        </span>@Override   <span style="white-space:pre">        </span>public Bitmap getBitmap(String key) {   <span style="white-space:pre">        </span>return lruCache.get(key);   <span style="white-space:pre">        </span>}   <span style="white-space:pre">        </span>};   <span style="white-space:pre">        </span>ImageLoader imageLoader = new ImageLoader(requestQueue, imageCache);   <span style="white-space:pre">        </span>return imageLoader;      <span style="white-space:pre">        </span>}}             
    转载请注明原文地址: https://ju.6miu.com/read-700201.html

    最新回复(0)