Java gets coordinates by transmitting address

Source: Internet
Author: User

 Packagecom.action;ImportJava.io.BufferedReader;ImportJava.io.InputStream;ImportJava.io.InputStreamReader;Importjava.net.HttpURLConnection;ImportJava.net.URL;Importjava.util.ArrayList;Importjava.util.List;ImportNet.sf.json.JSONArray;ImportNet.sf.json.JSONObject; Public classTest {/*** @Author Liuchao email:[email protected] * @data 2017-5-11 *@version1.0.1 *@paramargs*/          Public Staticstring Get (String urlall,string charset) {BufferedReader reader=NULL; String result=NULL; StringBuffer SBF=NewStringBuffer (); String useragent= "mozilla/5.0 (Windows NT 6.1) applewebkit/537.36 (khtml, like Gecko) chrome/29.0.1547.66 safari/537.36";//Simulation Browser           Try{URL URL=NewURL (Urlall); HttpURLConnection Connection=(HttpURLConnection) url.openconnection (); Connection.setrequestmethod ("GET"); Connection.setreadtimeout (30000); Connection.setconnecttimeout (30000); Connection.setrequestproperty ("User-agent", useragent);               Connection.connect (); InputStream is=Connection.getinputstream (); Reader=NewBufferedReader (NewInputStreamReader (IS, CharSet)); String Strread=NULL;  while((Strread = Reader.readline ())! =NULL) {sbf.append (strread); Sbf.append ("\ r");                } reader.close (); Result=sbf.tostring (); } Catch(Exception e) {e.printstacktrace (); }           returnresult; }           Public StaticList<object>Jeixi (String msg) {List<Object> list=NewArraylist<object>(); String JSON=msg; //jsonparser parser=new jsonparser ();Jsonobject obj=jsonobject.fromobject (msg); Jsonarray result= (Jsonarray) obj.get ("Result"); Jsonobject RESULT1= (jsonobject) result.get (0); Jsonobject Location= (jsonobject) result1.get ("Location"); List.add (Obj.get ("Status")); List.add (Result1.get ("City")); List.add (Result1.get ("District")); List.add (Result1.get ("Name")); List.add (Location.get ("LNG")); List.add (Location.get ("Lat")); List.add (Obj.get ("Message")); List.add (Result1.get ("UID")); List.add (Result1.get ("Businesss")); List.add (Result1.get ("Cityid"));         List.add (result); returnlist; }         Public Static voidMain (string[] args) {//TODO auto-generated Method Stub//String url= "http://api.map.baidu.com/place/v2/suggestion?query=Guang Bu Tun &region= Hubei province &city_limit=true&output=json&ak=grhqooqpoqzvm8nmrnvoqswejvggglqy, Hongshan District, Wuhan City, Hubei provinceString url2= "http://api.map.baidu.com/place/v2/suggestion?query=, Pudong New Area, Shanghai Shenjiang &region= Shanghai &city_limit=true &output=json&ak=grhqooqpoqzvm8nmrnvoqswejvggglqy "; String result=test.get (Url2, "UTF-8"); List<Object> result1=Test.jeixi (Result);  for(intI=0;i<result1.size (); i++) {System.out.println (Result1.get (i)); }    }}

Java gets coordinates by transmitting address

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.