JAva経緯度解析アドレス地理位置情報


/***
  *               
  * @param x
  * @param y
  * @throws IOException
  * @throws UnsupportedEncodingException
  */
 public String getaddressforxybyGooglehttpconnection(String x,String y) throws IOException
 {
  if(x.length() >9){x = x.substring(0,7);}
  if(y.length()>8){y = y.substring(0,6);}
  URL url = null;
  String mapurl="http://maps.google.cn/maps/geo?output=csv&key=abcdef&q=" +Float.parseFloat(y)/100000+ "," + Float.parseFloat(x)/100000 ;
  
  String address="                     ";//      
  StringBuffer strBuffer = new StringBuffer();
  HttpURLConnection connection = null;    
  DataInputStream in = null;
  try {
   url = new URL(mapurl);          
    connection = (HttpURLConnection) url.openConnection();
    connection.setRequestMethod("GET"); 
    connection.setUseCaches(false);   
    connection.setDefaultUseCaches(false);                    
    connection.setDoInput(true);  
    connection.setDoOutput(true);       
      connection.setConnectTimeout(1000);
      connection.setReadTimeout(1000);    
      in = new DataInputStream(connection.getInputStream());               
      int   all=   in.available();  
      int   code   =   connection.getResponseCode();   
      if(code   !=   connection.HTTP_OK)   
            {                           
                return address ;
            }   
            else   
            {   
             byte[]   b=   new   byte[all];   
            in.read(b);     
              String strAddress=   new   String(b,"UTF-8"); //GBK  2011-04-28
               String[] m_sAddress = strAddress.split(",");
                if (m_sAddress.length == 3)
                {
                 address = m_sAddress[2];
                }
                else
                {
                 address = "      ";
                }
                //address   =   new   String(b,"UTF-8"); //GBK  2011-04-28
   }                                                           
      connection.disconnect();
      in.close();         
     } catch (Exception e)
     {       
      address="                     ";//      
     } 
     finally
     { 
      connection.disconnect();
      in.close();
     }
  address = address.replace('"', ' ');
  address = address.replace("<?xml version= 1.0  encoding= GBK ?><R><code>0</code><msg>", "");
  address = address.replace("</msg></R>", "");
  return address;
 }