1.高德地图爬虫爬取数据并插入数据库
//API地址(http://lbs.amap.com/api/webservice/summary/)
publicstatic JSONObject getLngAndLat(Stringaddre, String type){
Stringurl = "http://restapi.amap.com/v3/place/text?parameters&extensions=all&key=1da8ea5d3653cdef862b805333f3465a&output=json&offset=20&page=1&city="+addre+"&keywords="+type; //解析
System.out.println(url);
long startTime1 = System.currentTimeMillis();//获取当前时间
String str = loadJSON(url);
JSONObject obj = JSONObject.fromObject(str);
long endTime1 = System.currentTimeMillis();//结束时间
System.out.println("url"+url);
System.out.println("obj"+obj);
System.out.println("解析程序运行时间"+(endTime1-startTime1)+"ms");
if(obj.get("status").toString().equals("1")){
List<JSONObject> list = obj.getJSONArray("pois");
System.out.println("测试地址集合1"+list);
for(JSONObject jx :list){
String tname = (String)jx.get("name");//名称
String address = (String)jx.get("address");//地址
String location = (String)jx.get("location");//经纬度
String tel = jx.get("tel").toString();//电话
String adname = (String)jx.get("adname"); //所属区名
String cityname = (String)jx.get("cityname"); //所属市名
String citycode = (String)jx.get("citycode"); //市区编码
String adcode = (String)jx.get("adcode"); //区域编码
String typecode = (String)jx.get("typecode"); //兴趣点类型编码
String pname = jx.get("pname").toString(); //所属省份
String pcode = jx.get("pcode").toString(); //省份编码
String postcode =jx.get("postcode").toString(); //邮编
List<Object> photos = (List<Object>) jx.get("photos"); //图片
StringBuffer a = new StringBuffer();
Object photoURL=null;
Scott sc = new Scott();
System.out.println("测试地址集合"+photos);
if(photos.size()==0) {
photoURL="无匹配图片";
sc.setCityname(cityname);
sc.setAdname(adname);
sc.setTname(tname);
sc.setAddress(address);
sc.setLocation(location);
sc.setTel(tel);
sc.setCitycode(citycode);
sc.setAdcode(adcode);
sc.setPcode(pcode);
sc.setPname(pname);
sc.setPostcode(postcode);
sc.setRemark("1");
a.append(photoURL);
a.append(" ");
sc.setTypecode(typecode);
sc.setPhotoURL(a.toString());
}else{
for (Object photo : photos) {
photoURL=((JSONObject)photo).get("url").toString();
sc.setCityname(cityname);
sc.setAdname(adname);
sc.setTname(tname);
sc.setAddress(address);
sc.setLocation(location);
sc.setTel(tel);
sc.setCitycode(citycode);
sc.setAdcode(adcode);
sc.setPcode(pcode);
sc.setPname(pname);
sc.setPostcode(postcode);
sc.setRemark("1");
sc.setTypecode(typecode);
a.append(photoURL);
a.append(" ");
sc.setPhotoURL(a.toString());
}
scottService.saveScottInfo(sc);
}
System.out.println("测试======================"+photoURL);
System.out.println("测试==市名:"+cityname+"区名:"+adname+"名称:"+tname+"地址:"+address+"经纬度:"+location+"电话:"+tel+"城市编码:"+citycode+"区域编码:"+adcode+"兴趣点类型编码:"+typecode+"所属省份:"+pname+"所属省份:"+pcode+"邮编:"+postcode+"图片:"+photos);
}
System.out.println("完成");
}
return obj;
}
/**
* 解析地址
*/
publicstatic String loadJSON (String uri) {
StringBuilder json = new StringBuilder();
try {
URL url = new URL(uri);
URLConnection yc =url.openConnection();
BufferedReader in = new BufferedReader(newInputStreamReader(yc.getInputStream(),"utf-8"));
String inputLine = null;
while ( (inputLine = in.readLine()) != null) {
json.append(inputLine);
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
return json.toString();
}
// public static voidmain(String[] args) {
//
// Scottmap.getLngAndLat("咸阳","酒店");
//
// }
}
所需jar包{
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.2.3</version>
</dependency>
}
2.前端点击查看按钮一次显示多张图片(后台返回jsonList集合)
easyui列 添加按钮超链接(点击也可跳转网址)
title:'图片操作',
field:'q',
width:80,
formatter:function(){
var btn = "<a class='editcls' id='check-picture' href='javascript:editRow();'>编辑</a>";
return btn;
//前端点击弹出窗口
<div onload="window(close);"id="searchImg"class="easyui-window" title="图片显示窗口" style="width:600px;height:600px"
data-options="iconCls:'icon-save',modal:true,closed:true">
<div class="easyui-layout" data-options="fit:true">
<div data-options="region:'center'"id="search">
<table>
<tr id=tr>
<td></td>
</tr>
</table>
</div>
</div>
</div> }
function editRow(){
if($("#dg").datagrid('getSelections').length==0){
$.messager.show({
title:'查看图片提示',
msg:'请选择要查看的图片',
timeout:5000,
showType:'slide'
})
}elseif($("#dg").datagrid('getSelections').length>1){
$.messager.show({
title:'查看图片提示',
msg:'只能选择一个信息进行查看',
timeout:5000,
showType:'slide'
})
}else {
//获取表单控件的数据
var scottId = $("#dg").datagrid('getSelected').scottId;
$.ajax({
url:"/scott22/scott/searchScottpictureById.do",
type:"post",
data:{"scottId":scottId},
dataType:"json",
//成功返回结果
// success:function(result){
// //跳转到图片页面
// window.open(result.photoUrl);
// }
success:function(data){
var json=eval(data);
var con=""
$.each(json,function(index,photoURL){
var s1=json[index].photoURL;
con+="<td ><img src='"+photoURL+"' width='200px' height='300px'/></td>";
});
;
$("#search").append($("#tr").append(con));
//打开窗口
$("#searchImg").window('open');
}
})
$('#searchImg').window({
onBeforeClose: function () { //当面板关闭之前触发的事件
$('#searchImg').window('close', true); //这里调用close 方法,true 表示面板被关闭的时候忽略onBeforeClose 回调函数。
$('#tr').window('clear');
}
});
}