Java gets addresses based on latitude and longitude

Source: Internet
Author: User

 Public classGetLocation { Public Static voidMain (string[] args) {//lat 39.97646//Log 116.3039String add = Getadd ("116.3039", "39.97646"); Jsonobject Jsonobject=jsonobject.fromobject (add); Jsonarray Jsonarray= Jsonarray.fromobject (jsonobject.getstring ("Addrlist")); Jsonobject j_2= Jsonobject.fromobject (Jsonarray.get (0)); String Alladd= J_2.getstring ("Admname"); String arr[]= Alladd.split (","); System.out.println ("Province:" +arr[0]+ "\ n City:" +arr[1]+ "\ n Area:" +arr[2]); }             Public Staticstring Getadd (string log, String lat) {//lat Small log large//parameter interpretation: Latitude, Longitude type 001 (100 for road, 010 for POI,001 for Gate, 111 for top three)String urlstring = "http://gc.ditu.aliyun.com/regeocoding?l=" +lat+ "," +log+ "&type=010"; String Res= ""; Try{URL URL=NewURL (urlstring); Java.net.HttpURLConnection Conn=(java.net.HttpURLConnection) url.openconnection (); Conn.setdooutput (true); Conn.setrequestmethod ("POST"); Java.io.BufferedReader in=NewJava.io.BufferedReader (NewJava.io.InputStreamReader (Conn.getinputstream (), "UTF-8"));               String Line;  while(line = In.readline ())! =NULL) {res+ = line+ "\ n";            } in.close (); } Catch(Exception e) {System.out.println ("Error in Wapaction,and e-is" +e.getmessage ());          } System.out.println (res); returnRes; }        }  

Java gets addresses based on latitude and longitude

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.