201112 月22
JAVA源码:将GPS、google地图经纬度坐标转换为百度地图坐标
package smsService; import org.apache.http.params.BasicHttpParams; import org.apache.http.params.HttpConnectionParams; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.params.CookiePolicy; import org.apache.http.client.params.HttpClientParams; import org.apache.http.entity.StringEntity; import org.apache.http.HttpResponse; import org.apache.http.HttpEntity; import org.json.me.JSONObject; import java.io.BufferedReader; import java.io.InputStreamReader; import smsService.cfg.Globals; import smsService.sms.StringUtil; import smsService.util.JWD; import smsService.util.SecBase64; /** Wizzer.cn */ public class baidu { public static void main(String args[]) { baidu b = new baidu(); b.getData("117.3094928", "31.875676"); System.out.println(""); } public static JWD getData(String jd, String wd) { JSONObject holder = new JSONObject(); String wizzer = ""; JWD jwd=null; try { BasicHttpParams httpParameters = new BasicHttpParams(); // Set the default socket timeout (SO_TIMEOUT) HttpConnectionParams.setConnectionTimeout(httpParameters, 15000); // in milliseconds which is the timeout for waiting for data. HttpConnectionParams.setSoTimeout(httpParameters, 15000); DefaultHttpClient client = new DefaultHttpClient(httpParameters); HttpClientParams.setCookiePolicy(client.getParams(), CookiePolicy.NETSCAPE);//CookiePolicy.BROWSER_COMPATIBILITY); String type="0";//详见百度坐标转换API文档示例 type=StringUtil.null2String(Globals.SYS_COM_CONFIG.get("sys.baidu.type")); HttpGet get = new HttpGet("http://api.map.baidu.com/ag/coord/convert?from="+type +"&to=4&x=" + jd + "&y=" + wd + "&callback=wizzer"); HttpResponse resp = client.execute(get); HttpEntity entity = resp.getEntity(); BufferedReader br = new BufferedReader(new InputStreamReader(entity .getContent(), "UTF-8")); StringBuffer sb = new StringBuffer(); String result = br.readLine(); while (result != null) { sb.append(result); result = br.readLine(); } String res = StringUtil.null2String(sb.toString()); if (res.indexOf("(") > 0 && res.indexOf(")") > 0) { String str = res.substring(res.indexOf("(") + 1, res.indexOf(")")); String err = res.substring(res.indexOf("error") + 7, res.indexOf("error") + 8); if ("0".equals(err)) { jwd=new JWD(); JSONObject js = new JSONObject(str); String x = new String(SecBase64.decode(js.getString("x").getBytes())); String y = new String(SecBase64.decode(js.getString("y").getBytes())); jwd.setX(x); jwd.setY(y); } } return jwd; } catch (Exception e) { e.printStackTrace(); return null; } } }
本文地址:https://wizzer.cn/archives/2140 , 转载请保留.
请问这是基于怎样一个思想的呢??
分析百度JS API得来的,没思想。- –
能否分享下代码??
文章内容里就是源码。
能否分享下源代码,以及jar包呢?
如上条回复。~
应该还有一个jar包什么的吧,,,里边提示错误好多啊
json-1.0.jar apache的包 还有自己写的类,实际源码就这一段而已。base64类见 http://www.wizzer.cn/?p=1359 文章里。
你好 能分享下全部源码么 最近正遇到这个问题 求教
如上回复,这里就是全部源码。- –
Google地图百度地图GPS经纬度偏移转换(JAVA)
http://my.oschina.net/Thinkeryjgfn/blog/402565