package com.jiuqi.mobile.lbs.intf.pub;
import java.io.Reader;
import java.io.StringReader;
import java.net.MalformedURLException;
import com.google.gson.Gson;
import com.google.gson.stream.JsonReader;
import com.jiuqi.mobile.lbs.intf.pub.baidu.geocoding.BaiduGisGeocoding;
import com.jiuqi.mobile.lbs.intf.pub.baidu.geocoding.GeocodingArea;
import com.jqmobile.core.utils.plain.StringUtils;
/**
* 2014/8/4号废弃,后续请使用com.jiuqi.mobile.lbs.intf2.geocode.BaiduGeocodeInfo
* @author MODI
*
*/
@Deprecated
public class BaiduGisInfo extends GisInfo{
/**
*
*/
private static final long serialVersionUID = 8736173631287856230L;
private BaiduGisGeocoding bgg;
public BaiduGisInfo() {
super();
}
public static void main(String[] args) {
BaiduGisInfo info = new BaiduGisInfo(113.6500047,34.789672);
System.out.println(info.getXmlStr());
}
public BaiduGisInfo(double longitude2, double latitude2) {
super(longitude2, latitude2);
}
@Override
protected void doRequest() {
try {
String resultJson = request(getUrl());
setXmlStr(resultJson);
String start = "renderReverse&&renderReverse(";
if(resultJson.startsWith(start)){
resultJson = resultJson.substring(start.length(), resultJson.length()-1);
Gson gson = new Gson();
Reader in = new StringReader(resultJson);
JsonReader jr = new JsonReader(in );
bgg = gson.fromJson(jr, BaiduGisGeocoding.class);
// private String recid;//lbsinfo赋值(使用者赋值)
// private String province;// 省份
// private String city;// 地区
// private String code;// 区号
// private String country;// 县、区
if(0 == bgg.getStatus() && null != bgg.getResult()){
GeocodingArea area = bgg.getResult().getAddressComponent();
if(null != area){
setProvince(area.getProvince());
setCity(area.getCity());
// setCode(bgg.getResult().getCityCode());
setCountry(area.getDistrict());
}
// private String poi;// 两个标志性建筑
if(null != bgg.getResult().getPois()){
String poi="";
for(int i=0; i<2 && i<bgg.getResult().getPois().length; i++){
poi += bgg.getResult().getPois()[i].getName();
}
setPoi(poi);
}
// private String content;// 位置详情
String str = bgg.getResult().getBusiness();
if(StringUtils.isEmpty(str, true)){
str = bgg.getResult().getFormatted_address();
}else{
str +=";" + bgg.getResult().getFormatted_address();
}
setContent(str);
// @DBColumn(length=1000)
// private String xCross;// 交叉路口
//// @DBColumn(length=2000)
// @DBColumn(type = DBColumn.Type_Text)
// private String xmlStr;// xml原始文本
// @DBColumn(length=1000)
// private String str1;// 标准建筑原始文本
}
// private double longitude;// 经度
// private double Latitude;// 纬度
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
private String getUrl() {
String strUrl = "http://api.map.baidu.com/geocoder/v2/?ak=SXKQpoIQB6cRKSbj4W2YAZGB&coordtype=gcj02ll&callback=renderReverse&location="+getLatitude()+","+getLongitude()+"&output=json&pois=1";
return strUrl;
}
public BaiduGisGeocoding getBaiduGisGeocoding() {
return bgg;
}
}