* Access to the Google maps API address parser by IP addresses may be permanently blocked. * * @param latitude * Latitude * @param Longitude * Longitude * @return Jsonobject * * @author Lvqiyong */ /* Examples are as follows: * { "Name": "29.871398,121.5817", ' Status ': { "Code": 200, "Request": "GeoCode" }, "Placemark": [{ "id": "P1", "Address": "No. No. 360 Zhongxing Road, Jiangdong District, Ningbo, Zhejiang, China: 315040", "Addressdetails": { "Accuracy": 8, "Country": { "Administrativearea": { "Administrativeareaname": "Zhejiang Province", "Locality": { "Dependentlocality": { "Dependentlocalityname": "Jiangdong District", "Thoroughfare": { "Thoroughfarename": "No. No. 360 Zhongxing Road" } }, "Localityname": "Ningbo" } }, "CountryName": "China", "Countrynamecode": "CN" } }, "Extendeddata": { "Latlonbox": { "North": 29.8737610, "South": 29.8710630, "East": 121.5832290, "West": 121.5805310 } }, "Point": { "Coordinates": [121.5818800, 29.8724120, 0] } } ] }*/ public static Jsonobject getjsonaddr (string latitude, string longitude) { It can be http://maps.google.cn/maps/geo?output=csv&key=abcdef&q=%s,%s, but it's an English address. The key can be casually written a key=abc Output=csv, or it can be XML or JSON, the default way is to Output=json String url = string . Format ( "Http://ditu.google.cn/maps/geo?key=abcdef&q=%s,%s", latitude, longitude); HttpGet httpget = new HttpGet (URL); HttpClient client = new Defaulthttpclient (); HttpResponse response; StringBuilder StringBuilder = new StringBuilder (); try { Response = Client.execute (HttpGet); /* httpentity entity = response.getentity (); InputStream stream = Entity.getcontent (); int b; while ((b = stream.read ())!=-1) { Stringbuilder.append ((char) b); }*/ httpentity entity = response.getentity (); BufferedReader br = new BufferedReader (New InputStreamReader (Entity . getcontent ()); String result = Br.readline (); while (result!= null) { Stringbuilder.append (result); result = Br.readline (); } catch (Clientprotocolexception e) { catch (IOException e) { } Jsonobject jsonobject = new Jsonobject (); try { Jsonobject = new Jsonobject (stringbuilder.tostring ()); catch (Jsonexception e) { E.printstacktrace (); } return jsonobject; } |