Obtain the address location based on the longitude and latitude

Source: Internet
Author: User
// Obtain the geographic position private string getlocation (situde ws itude) throws exception {string resultstring = "";/** the get method is used here, directly add the parameter to the URL */string urlstring = string. format ("http://maps.google.cn/maps/geo? Key = abcdefg & Q = % s, % s ", required. latitude, longitude. longpolling); log. I ("url", urlstring);/** create httpclient */httpclient client = new defaulthttpclient (); /** use the get Method */httpget get = new httpget (urlstring); try {/** to initiate a GET request and obtain the returned data */httpresponse response = client.exe cute (get ); httpentity entity = response. getentity (); bufferedreader buffreader = new bufferedreader (New inputstreamreader (entity. getcontent (); string Buffer strbuff = new stringbuffer (); string result = NULL; while (result = buffreader. Readline ())! = NULL) {strbuff. append (result);} resultstring = strbuff. tostring ();/** parse JSON data to obtain the physical address */If (resultstring! = NULL & resultstring. length ()> 0) {jsonobject = new jsonobject (resultstring); jsonarray = new jsonarray (jsonobject. get ("placemark "). tostring (); resultstring = ""; for (INT I = 0; I <jsonarray. length (); I ++) {resultstring = jsonarray. getjsonobject (I ). getstring ("Address") ;}} catch (exception e) {Throw new exception ("An error occurred while obtaining the physical location:" + E. getmessage ();} finally {Get. abort (); client = NULL;} return resultstring ;}

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.