Title, with the mobile phone Baidu to obtain GPS-related coordinates information and the real coordinate information has a certain deviation exists, as to why the deviation, for the moment.
The following thing I searched for is to reduce the error to a minimum method, for reference only.
Baidu latitude and longitude coordinates and Google latitude and longitude coordinates are converted. Use the URL below to convert the original coordinates or Google coordinates into the coordinates of Baidu
http://api.map.baidu.com/ag/coord/convert?from=2&to=4&x=114.324821&y=22.605812, will get the Base64 character, Restore is the true latitude and longitude.
There are four parameters in the request interface:
where the values corresponding to the From and to are: 0 true coordinates, 2google coordinates, 4BAIDU coordinates.
From: The coordinate system being converted
To: Convert to this coordinate system
X: Longitude
Y: Latitude
There are three keys in the interface answer,
Answer format such as: {"error": 0, "x": "Mte2ljmymtyymzg4mjiz", "Y": "Ndaumdy2nde2mjc4nzmx"}
where x and y are the required values
The application is as follows:
Package Com.baidumap error correction; Import Java.io.bufferedreader;import Java.io.ioexception;import Java.io.inputstream;import Java.io.inputstreamreader;import Java.net.httpurlconnection;import Java.net.url;import Com.google.gson.Gson; Import Com.sun.xml.internal.messaging.saaj.util.base64;class baidumapmodifyvalue{string error; String x; String Y;public string GetError () {return error;} public void SetError (String error) {this.error = error;} Public String GetX () {return x;} public void SetX (String x) {this.x = x;} Public String GetY () {return y;} public void Sety (String y) {this.y = y;}} public class Bmapgismodify {public static String converttostring (InputStream inputstream) {InputStreamReader INP Utstreamreader = new InputStreamReader (InputStream); BufferedReader BufferedReader = new BufferedReader (InputStreamReader); StringBuilder result = new StringBuilder (); String line = null; try {while (line = Bufferedreader.readline ()) = null) { Result.append (line + "\ n"); }} catch (IOException e) {e.printstacktrace (); } finally {try{inputstreamreader.close (); Inputstream.close (); Bufferedreader.close (); }catch (IOException e) {e.printstacktrace (); }} return result.tostring (); }/* * In the GIS information, "X, Y" XY represents the latitude and longitude * out of the GIS correction information, the content "x, y" XY represents the latitude and longitude * */public static String Modifygis (string valuexy) { SYSTEM.OUT.PRINTLN ("Original GIS value:" +valuexy); string[] Gisxy = Valuexy.split (","); String GISX = gisxy[0]; String gisy = gisxy[1]; /* Fix the connection address * the values corresponding to the From and to are: 0 true coordinates, 2google coordinates, 4BAIDU coordinates. From: Converted coordinate system to: convert to this coordinate system x: Longitude y: Latitude */String Urlvalue = "http://api.map.baidu.com/ag/coord/convert?from=0&to=4 &x= "+gisx+" &y= "+gisy; HttpURLConnection urlconnection = null; JSON parse callback value String responsestr = ""; try{url url = new URL (urlvalue); URLConnection = (httpurlconnection) url.openconnection (); Get Request Define://urlconnection.setrequestmethod ("get"); Urlconnection.connect (); Connection Response from Test servlet//system.out.println ("Connection Response from Test servlet"); InputStream InputStream = Urlconnection.getinputstream (); Convert Stream to String responsestr = ConvertToString (InputStream); System.out.println (RESPONSESTR); }catch (IOException e) {System.out.println ("Baidu GIS correction, URL forced parsing, abnormal"); }finally{Urlconnection.disconnect (); } baidumapmodifyvalue result = new Gson (). Fromjson (Responsestr, Baidumapmodifyvalue.class); if (!result.error equals ("0")) {System.out.println ("Baidu map corrects GIS, returns result marker bit not 0, exception"); return "Resulterror";} else{String GISXY_OK = Base64.base64decode (Result.getx ()) + "," +base64.base64decode (result.geTY ()); SYSTEM.OUT.PRINTLN ("Correcting GIS values:" +GISXY_OK); return GISXY_OK; }} public static void Main (string[] args) {/* Baidu map Pickup coordinate system URL Connection * HTTP://API.MAP.BAIDU.COM/LBSAPI/GETPOINT/INDEX.HTML?QQ-P F-to=pcqq.group * tick ' coordinate reverse ', you can do numerical coordinates to reverse the geographical coordinates * */String Gisinfo = "133.94404224820853,21.537722890239518"; Modifygis (Gisinfo);}}
Baidu Map GPS Information correction