Baidu Map API Geocoding Fault resolution cases and ideas, Baidu banned geocoding httpget access to edit the way

Source: Internet
Author: User



Error description

To the enterprise to do the app embedded in the use of GPS address information into the actual address of the function, using the Baidu map of the geocoding function, from the beginning of Wednesday, there have been user feedback, using the location can not obtain address information error, a small range, it is the user's own problems, no care , but in the Thursday, it began to explode in large areas;

Solution to find out whether the Baidu API changes

Because the recent Android app did not do any updates, so the suspicion is not Baidu's API has been modified, but looked at the following document, also did not change, and according to Baidu before the habit should be backward compatible;

See if the key expires.

Login Baidu Map API management Console, see the next key is not expired, and through the code can also be accessed;

After the key has been replaced, the problem remains after the call;

Check Android code

1, check the code used for the downgrade, found that the use of HttpGet way to obtain, consider changing the post method to see if it can solve the problem;

2, replaced by HttpPost mode, the problem is resolved, you can confirm that Baidu modified the API to obtain the way, rejected the get way live rejected Android code inside HttpGet Way;

public static string Geturldata (string url)
Throws Exception {
int ReturnCode = 0;
url = checkurl (URL);
HttpGet get = new HttpGet (URL);
String strresult = "";
Httpparams httpparams = new Basichttpparams ();
Connmanagerparams.settimeout (Httpparams, 3000);

Get.setheader ("Text/html;charset", "Utf-8″");

Connmanagerparams.settimeout (Httpparams, 3000);

Httpconnectionparams.setconnectiontimeout (Httpparams, 4000);

Httpconnectionparams.setsotimeout (Httpparams, 8000);
Schemeregistry Schreg = new Schemeregistry ();
Schreg.register ("http", Plainsocketfactory
. Getsocketfactory (), 80));

/* HttpClient */
Clientconnectionmanager conmgr = new Threadsafeclientconnmanager (
Httpparams, Schreg);
HttpClient HttpClient = new Defaulthttpclient (conmgr, httpparams);

HttpClient HttpClient =new defaulthttpclient ();
try{
HttpResponse response = Httpclient.execute (get);
HttpResponse response = new Defaulthttpclient (). Execute (GET);
ReturnCode = Response.getstatusline (). Getstatuscode ();
if (ReturnCode = = 200) {
Strresult =entityutils.tostring (Response.getentity (), "Utf-8″");

String result = entityutils.tostring (Response.getentity (), "Utf-8″");
KONKALOG.I (Response.getallheaders (). toString ());
for (int i=0;i<response.getallheaders (). length;i++) {
KONKALOG.I (Response.getallheaders () [I].getname (), Response.getallheaders () [I].getvalue ()];
}
COM.EASYBIZ.UTIL.KONKALOG.I ("Posturldata", strresult);

return strresult;

}else{
COM.EASYBIZ.UTIL.KONKALOG.I ("Posturldata", ReturnCode + "");
Return "" +returncode;
}
}catch (Exception e) {
Return "An unknown error occurred";
}
}

public static string Posturldata (string url)
Throws Exception {
int ReturnCode = 0;
url = checkurl (URL);
HttpPost post = new HttpPost (URL);
String strresult = "";
HttpClient HttpClient = new Defaulthttpclient ();

HttpResponse response = Httpclient.execute (POST);
ReturnCode = Response.getstatusline (). Getstatuscode ();
if (ReturnCode = = 200) {
Strresult =entityutils.tostring (Response.getentity ());
COM.EASYBIZ.UTIL.KONKALOG.I ("Posturldata", strresult);
ErrorCode = 200;
return strresult;

}else{
COM.EASYBIZ.UTIL.KONKALOG.I ("Posturldata", ReturnCode + "");
Errordescript = returncode+ "";
Return "" +returncode;
}

}

/**
* Common classes of HttpPost
* @param URL Address
* @param params parameter
* @return Return String type
* @throws Exception
*/
public static string Posturldata (string url, arraylist<namevaluepair> params)
Throws Exception {
int ReturnCode = 0;
url = checkurl (URL);
HttpPost post = new HttpPost (URL);

String strresult = "";

COM.EASYBIZ.UTIL.KONKALOG.I ("Posturldata", params.tostring ());
Post.setentity (New urlencodedformentity (params, HTTP. Utf_8));
Httpparams httpparams = new Basichttpparams ();

Connmanagerparams.settimeout (Httpparams, 3000);

Connmanagerparams.settimeout (Httpparams, 3000);

Httpconnectionparams.setconnectiontimeout (Httpparams, 120000);

Httpconnectionparams.setsotimeout (Httpparams, 120000);
Schemeregistry Schreg = new Schemeregistry ();
Schreg.register (New Scheme ("http", Plainsocketfactory.getsocketfactory (), 80));
Clientconnectionmanager conmgr = new Threadsafeclientconnmanager (
Httpparams, Schreg);
HttpClient HttpClient = new Defaulthttpclient (conmgr, httpparams);

HttpClient HttpClient =new defaulthttpclient ();
try{

HttpResponse response = Httpclient.execute (POST);

ReturnCode = Response.getstatusline (). Getstatuscode ();
Strresult =entityutils.tostring (Response.getentity ());
if (ReturnCode = = 200) {

COM.EASYBIZ.UTIL.KONKALOG.I ("Posturldata", strresult);
return strresult;

}else{
COM.EASYBIZ.UTIL.KONKALOG.I ("Posturldata", ReturnCode + "");
Errordescript = "Login Failed";
Return "" +returncode;
}
}catch (Exception e) {
COM.EASYBIZ.UTIL.KONKALOG.I ("Posturldata", strresult);
E.printstacktrace ();
Errordescript = "Network connection failed, please check WiFi or data connection is normal";
Return "Network connection failed, please check WiFi or data connection is normal";
}
}

method_url = Method_url + "? Output=json" + "&AK=DLWP0PMEQQKYFBBNTHGSLLJM" + "&location=" + loc.getlatitude () + "," +loc.getlongitude ();

strresult = Httpcomm.posturldata (method _url));//public method call see above

&NBSP;

&NBSP;

3, but modified to post method, found that there will be 10 calls, 3 times will appear to fail, re-check the code, found that the practical way is not httppost, replaced by the standard way, the problem is resolved;

Method_url = Method_url + "? Output=json" + "&AK=DLWP0PMEQQKYFBBNTHGSLLJM" + "&location=" + loc.getLatitude () + "," +loc.getlongitude ();
strresult = Httpcomm.posturldata (Method_url));//common method invocation see above

Change the revision here to

arraylist<namevaluepair> params = new arraylist<namevaluepair> ();

Basicnamevaluepair Basevaluepair = new Basicnamevaluepair ("Output", "json");

Params.add (Basevaluepair);

Basevaluepair = new Basicnamevaluepair ("Location", Loc.getlatitude () + "," +loc.getlongitude ());

Params.add (Basevaluepair);
Basevaluepair = new Basicnamevaluepair ("AK", "DLWP0PMEQQKYFBBNTHGSLLJM");
Params.add (Basevaluepair);

strresult = Httpcomm.posturldata (method_url,params);

====================================================

Please pay attention to my number @it51share

650) this.width=650; "width=" 186 "src=" Http://www.it51share.com/wp-content/uploads/2014/10/qrcode_for_gh_ 77c8f9e8439a_430-2.jpg "height=" "style=" border:0px;height:auto;vertical-align:middle;/>

Welcome to join: 179203853 (Anhui Development Group)

====================================================

Articles related to this article
    • Httpurlconnection,http Clinet,whitch

    • Explore key success factors of enterprise mobile informatization Landing

    • Mobile Office Concept I'm afraid it's really going to fire!

    • Friends League Index: Large screen, high-resolution devices become popular trend, women and low-age users market potential

    • Comparison of four HTML5 mobile application frameworks for JQTouch, Jquerymobile, Sencha Touch, Titaniummobile

    • 4 reasons Facebook has abandoned HTML5

    • Android Development: Turn off the soft keyboard in EditText

    • Android take pictures and save (compress, decompose)

    • Android WebView Related properties

    • Determine if an app is installed under your phone's browser and decide whether to open the app

    • Designed for Mobile, Part I: Information architecture

    • Top six enterprise mobile application platforms that CIOs are most concerned about


This article is from the "Unknown Programmer" blog, please be sure to keep this source http://wmcxy.blog.51cto.com/2509483/1574842

Baidu Map API Geocoding Fault resolution cases and ideas, Baidu banned geocoding httpget access to edit the way

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.