首先将LBS(版本服务器域名)和USER(ak,geotable_id等)的基本信息分别定义在 LBSINFO.java 和 USERINFO.java 再将各个请求对象(XXObject)和相应的响应(XXJson)对象根据API参数封装,若包含自定义字段,则继承其父类 结构如下:
1、LBSINFO.java
package com.xeonmic.lbs.vo;
/** * @author Xeon * @version 3.0 */
public class LBSINFO {
public static final String LBSPOIURL = "http://api.map.baidu.com/geodata/v3/poi/";
//public static final String LBS = "";
}
2、USERINFO.java
package com.xeonmic.lbs.vo;
/** * @author Xeon * @version 3.0 */
public class USERINFO {
public static final String ak="YourKey";//用户AK
public static final String geotable_id="YourTableId";//表id
public static final int coord_type=1;//用户上传的坐标类型
public static final String sn="";//用户的权限签名(可选)
}
3、POI.java
/** * */
package com.xeonmic.lbs.vo;
import java.util.List;
/** * 位置数据(poi)实体类 * @author Xeon * @version 3.0 */
public class POI {
private int id;//唯一标识
private List<Double> location;//坐标
private String province;//省名称
private int city_id;//市id
private String city;//市名
private String district;//区名
private String title;//名称
private String address;//地址
private int coord_type;//用户上传的坐标的类型
private String tags;//标签
private String geotable_id;//表主键
private String create_time;//创建时间
private String modify_time;//修改时间
/*Setters and Getter*/
/** * 完整的构造函数 * @param id * @param location * @param province * @param city_id * @param city * @param district * @param title * @param address * @param coord_type * @param tags * @param geotable_id * @param create_time * @param modify_time */
public POI(int id, List<Double> location, String province, int city_id,
String city, String district, String title, String address,
int coord_type, String tags, String geotable_id, String create_time,
String modify_time) {
//super();
this.id = id;
this.location = location;
this.province = province;
this.city_id = city_id;
this.city = city;
this.district = district;
this.title = title;
this.address = address;
this.coord_type = coord_type;
this.tags = tags;
this.geotable_id = geotable_id;
this.create_time = create_time;
this.modify_time = modify_time;
}
/** * 必须的构造函数 * @param id * @param location * @param city_id * @param city * @param geotable_id * @param create_time * @param modify_time */
public POI(int id, List<Double> location, int city_id, String city,
String geotable_id, String create_time, String modify_time) {
this.id = id;
this.location = location;
this.city_id = city_id;
this.city = city;
this.geotable_id = geotable_id;
this.create_time = create_time;
this.modify_time = modify_time;
}
/* (非 Javadoc) * @see java.lang.Object#toString() */
@Override
public String toString() {
return "POI [id=" + id + ", location=" + location + ", province="
+ province + ", city_id=" + city_id + ", city=" + city
+ ", district=" + district + ", title=" + title + ", address="
+ address + ", coord_type=" + coord_type + ", tags=" + tags
+ ", geotable_id=" + geotable_id + ", create_time="
+ create_time + ", modify_time=" + modify_time + "]";
}
}
4、POIObject.java
package com.xeonmic.lbs.vo;
/** * @author Xeon * @version 3.0 */
public class POIObject extends LBSObject {
/** * @param ak * @param geotable_id * @param coord_type */
protected String title;//poi名称
protected String address;//地址
protected String tags;//标签
protected String latitude;//
protected String longitude;//
//protected String coord_type;//
//protected String geotable;//
//protected String ak;//
//protected String sn;//
/** * 构造函数 * @param title * @param address * @param tags * @param latitude * @param longitude */
public POIObject( String title, String address, String tags, String latitude,
String longitude) {
this.title = title;
this.address = address;
this.tags = tags;
this.latitude = latitude;
this.longitude = longitude;
}
}
5、POIFindObject.java
package com.xeonmic.lbs.vo;
/** * @author Xeon * @version 3.0 */
public class POIFindObject extends LBSObject {
public String title;//记录(数据)名称
public String tags;//记录的标签(用于检索筛选)
public String bounds;//查询的矩形区域
public int page_index;//分页索引
public int page_size;//分页数目
/** * @param title * @param tags * @param bounds * @param page_index * @param page_size */
public POIFindObject(String title, String tags, String bounds,
int page_index, int page_size) {
super();
this.title = title;
this.tags = tags;
this.bounds = bounds;
this.page_index = page_index;
this.page_size = page_size;
}
/*Setters and Getter*/
/*public Map<String, Object> toMap() { Map<String, Object> map=new HashMap<String,Object>(); map.put("title", title); map.put("bounds", bounds); map.put("tags", tags); map.put("page_index", page_index); map.put("page_size", page_size); map.put("ak", ak); map.put("geotable_id", geotable_id); if(!"".equals(sn)){ map.put("sn", sn); } //map.put(key, value)//添加自定义字段键-值对 return map; }*/
public String toURL() {
String URL ="?";
URL+="title="+title;
if (!"".equals(bounds)) {
URL+="bounds="+bounds+"&";
}
if (!"".equals(tags)) {
URL+="tags="+tags+"&";
}
URL+="page_size="+page_size+"&";
URL+="page_index="+page_index+"&";
URL+="ak="+ak+"&";
if (!"".equals(sn)) {
URL+="sn="+sn+"&";
}
URL+="geotable_id="+geotable_id+"";
return URL;
}
}
6、POIFindJson.java
package com.xeonmic.lbs.vo;
import java.util.List;
/** * 查询指定条件POI数据的响应参数类 * @author Xeon * @version 3.0 */
public class POIFindJson {
protected int status;//状态码
protected String message;//响应的信息
protected int size;//返回数据条数
protected int total;//全部的数据条数
protected List<POI> pois;//poi结果列表
/*Setters and Getter*/
public POIFindJson(int status, String message, int size, int total,
List<POI> pois) {
this.status = status;
this.message = message;
this.size = size;
this.total = total;
this.pois = pois;
}
@Override
public String toString() {
return "POIFindJson [status=" + status + ", message=" + message
+ ", size=" + size + ", total=" + total + ", pois=" + pois
+ "]";
}
}