Import Java.io.BufferedReader; Import java.io.IOException; Import Java.io.InputStreamReader; Import java.io.UnsupportedEncodingException; Import java.net.MalformedURLException; Import Java.net.URL; Import java.net.URLConnection; public class Demo {public static void main (string[] args) {String addr = getaddr ("35.8616600", "104.1953970"); System.out.println (addr); Getcoordinate ("China"); /** * The reverse resolution of the address according to latitude and longitude, sometimes need to try more than a few times * Note: (Excerpt: Http://code.google.com/intl/zh-CN/apis/maps/faq.html * The number of address resolution requests submitted is limited.) If you receive more than 2,500 address resolution requests from an IP address over a 24-hour period, or if the rate of address resolution requests from an IP * address is too fast, the Google map API Encoder will start responding with a 620 status code. If the address resolver is used too much, access to the Google map API address parser from that IP * address may be permanently blocked. * @param latitude * latitude * @param longitude * Longitude * @return/public static string Getaddr (string latitude, String Longitu de) {String addr = ""; can also be http://maps.google.cn/maps/geo?output=csv&key=abcdef&q=%s,%s, but the solution is the English address//key can be casually write a KEY=ABC// Output=csv can also be XML or JSON, but the data returned using CSV is the simplest and easiest to parse String urls = String.Format ("http:ditu.google.cn/maps/geo?output=csv&key=abcdef&q=%s,%s ", latitude, longitude); URL myurl = null; URLConnection httpsconn = null; try {myurl = new URL (URL);} catch (Malformedurlexception e) {e.printstacktrace (); return null;} try {httpsconn = (url Connection) myurl.openconnection (); if (httpsconn!= null) {InputStreamReader INSR = new InputStreamReader (Httpsconn.getinputstream (), "UTF-8"); BufferedReader br = new BufferedReader (INSR); String data = null; if (data = Br.readline ())!= null) {System.out.println (data); string[] Retlist = Data.split (","); if (Retlist.length > 2 && ("retlist[0. equals")) {addr = retlist[2]; addr = Addr.replace ("/", "");} else {addr = "";}} Insr.close (); The catch (IOException e) {e.printstacktrace (); return null;} return addr; public static void Getcoordinate (String addr) {string Addrs = ""; String address = null; try {address = Java.net.URLEncoder.encode (addr, "UTF-8");} catch (Unsupportedencodingexception E1) {E1.printStackTrace (); }; String output = "csv"; String key = "abc"; String url = String.Format ("http://maps.google.com/maps/geo?q=%s&output=%s&key=%s", address, output, key); URL myurl = null; URLConnection httpsconn = null; Make transcoding try {myurl = new URL (URL);} catch (Malformedurlexception e) {e.printstacktrace ();} try {httpsconn = (Urlconnec tion) myurl.openconnection (); if (httpsconn!= null) {InputStreamReader INSR = new InputStreamReader (Httpsconn.getinputstream (), "UTF-8"); BufferedReader br = new BufferedReader (INSR); String data = null; if (data = Br.readline ())!= null) {System.out.println (data); string[] Retlist = Data.split (","); /* String latitude = retlist[2]; String longitude = retlist[3]; System.out.println ("latitude" + latitude); System.out.println ("longitude" + longitude); */if (Retlist.length > 2 && ("Retlist[0")) {Addrs = retlist[2]; Addrs = Addr.replace ("/", ""); else {Addrs = "";}} Insr.close (); } catch (IOException e) {e.printstacktRace (); } System.out.println (Addrs); } ============================ domestic detailed address has other address resolution server to provide more detailed address resolution services, or the data request to the server, the next time the user requests from their own server request, can not find the address of the Google request.
From: http://hi.baidu.com/zdz8207/blog/item/f8bbc55c36a32657faf2c025.html