Java代码 使用了 httpclient包
1.public String getGoogleLocation() throws ClientProtocolException, IOException 2. { 3. URIBuilder builder = new URIBuilder(); 4. builder.setScheme("http").setHost("maps.googleapis.com").setPath("/maps/api/geocode/xml") 5. .setParameter("address",address+"南京"+"地铁站") 6. .setParameter("sensor","false"); 7. URI uri = null; 8. try { 9. uri = builder.build(); 10. System.out.println(uri); 11. } catch (URISyntaxException e) { 12. // TODO Auto-generated catch block 13. e.printStackTrace(); 14. } 15. HttpGet httpget = new HttpGet(uri); 16.//'http.protocol.cookie-policy':定义了用于HTTP状态管理的cookie规范的名字。这个参数期望得到一个java.lang.String类型的值。如果这个参数没有被设置,那么合法的日期格式就是CookieSpec实现规范的值。17. httpget.getParams().setParameter("http.protocol.cookie-policy", 18. CookiePolicy.BROWSER_COMPATIBILITY); 19. 20. HttpClient httpclient = new DefaultHttpClient(); 21. HttpResponse response = httpclient.execute(httpget); 22. HttpEntity entity = response.getEntity(); 23. if (entity != null) { 24. 25. String xml = EntityUtils.toString(entity); 26. return xml; 27. } 28. return ""; 29. } 百度获取时参数如下1.builder.setScheme("http").setHost("api.map.baidu.com").setPath("/geocoder/v2/") 2. .setParameter("ak", ak) 3. .setParameter("output",output) 4. .setParameter("address",address) 5. .setParameter("city",city); 获取信息对比Baidu 1.<?xml version="1.0" encoding="utf-8" ?> 2.<GeocoderSearchResponse> 3. <status>0</status> 4. <result> 5. <location> 6. <lat>32.068604458801</lat> 7. <lng>118.76505691316</lng> 8. </location> 9. <precise>0</precise> 10. <confidence>25</confidence> 11. <level>区县</level> 12. </result> 13.</GeocoderSearchResponse> Google 1.<?xml version="1.0" encoding="UTF-8"?> 2.<GeocodeResponse> 3. <status>OK</status> 4. <result> 5. <type>subway_station</type> 6. <type>train_station</type> 7. <type>transit_station</type> 8. <type>establishment</type> 9. <formatted_address>Gulou, Nanjing, China, 210008</formatted_address> 10. <address_component> 11. <long_name>Gulou</long_name> 12. <short_name>Gulou</short_name> 13. <type>subway_station</type> 14. <type>train_station</type> 15. <type>transit_station</type> 16. <type>establishment</type> 17. </address_component> 18. <address_component> 19. <long_name>Gulou</long_name> 20. <short_name>Gulou</short_name> 21. <type>sublocality</type> 22. <type>political</type> 23. </address_component> 24. <address_component> 25. <long_name>Nanjing</long_name> 26. <short_name>Nanjing</short_name> 27. <type>locality</type> 28. <type>political</type> 29. </address_component> 30. <address_component> 31. <long_name>China</long_name> 32. <short_name>CN</short_name> 33. <type>country</type> 34. <type>political</type> 35. </address_component> 36. <address_component> 37. <long_name>210093</long_name> 38. <short_name>210093</short_name> 39. <type>postal_code</type> 40. </address_component> 41. <geometry> 42. <location> 43. <lat>32.0589420</lat> 44. <lng>118.7837680</lng> 45. </location> 46. <location_type>APPROXIMATE</location_type> 47. <viewport> 48. <southwest> 49. <lat>32.0575930</lat> 50. <lng>118.7824190</lng> 51. </southwest> 52. <northeast> 53. <lat>32.0602910</lat> 54. <lng>118.7851170</lng> 55. </northeast> 56. </viewport> 57. </geometry> 58. </result> 59.</GeocodeResponse> 可以看到google地图查询得出的结果更详细。而且一些站名在Baidu下面无法获取但是用google可以获取