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 ");
}
/**
* Reverse Address Resolution Based on latitude and longitude. Sometimes you need to try multiple times.
* Note: (from: http://code.google.com/intl/zh-CN/apis/maps/faq.html
* Is there a limit on the number of Address Resolution requests submitted ?) If you receive more than 2500 resolution requests from an IP address within the 24-hour period
* The Request Rate for address resolution submitted by the address is too high. The Google map API encoder starts to respond with the 620 status code. If the IP address parser is still used too much
* Access to the Google map API address parser may be permanently blocked.
*
* @ Param latitude
* Latitude
* @ Param longpolling
* Longitude
* @ Return
*/
Public static string getaddr (string latitude, string longbench ){
String ADDR = "";
// Can also be a http://maps.google.cn/maps/geo? Output = CSV & Key = abcdef & Q = % s, % s, but the resolved English address is
// You can write a key = ABC at will.
// Output = CSV, which can also be XML or JSON. However, the data returned by CSV is the most concise and convenient for parsing.
String url = string. Format (
"Http://ditu.google.cn/maps/geo? Output = CSV & Key = abcdef & Q = % s, % s ",
Latitude, longpolling );
URL myurl = NULL;
Urlconnection httpsconn = NULL;
Try {
Myurl = new URL (URL );
} Catch (malformedurlexception e ){
E. printstacktrace ();
Return NULL;
}
Try {
Httpsconn = (urlconnection) 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 & ("200". Equals (retlist [0]) {
ADDR = retlist [2];
ADDR = ADDR. Replace ("\"","");
} Else {
ADDR = "";
}
}
Insr. Close ();
}
} 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;
// Transcode
Try {
Myurl = new URL (URL );
} Catch (malformedurlexception e ){
E. printstacktrace ();
}
Try {
Httpsconn = (urlconnection) 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 longpolling = retlist [3];
System. Out. println ("latitude" + latitude );
System. Out. println ("longitude" + longpolling );
*/
If (retlist. length> 2 & ("200". Equals (retlist [0]) {
Addrs = retlist [2];
Addrs = ADDR. Replace ("\"","");
} Else {
Addrs = "";
}
}
Insr. Close ();
}
} Catch (ioexception e ){
E. printstacktrace ();
}
System. Out. println (addrs );
}
}
======================================
There are other address resolution servers in China that provide more detailed address resolution services, or put data requests on your server. The next user request is sent from your server, if the address is not found, go to Google again.
From: http://hi.baidu.com/zdz8207/blog/item/f8bbc55c36a32657faf2c025.html