首页 星云 工具 资源 星选 资讯 热门工具
:

PDF转图片 完全免费 小红书视频下载 无水印 抖音视频下载 无水印 数字星空

Java 调用Google Map Api解析地址,解析经纬度实例

后端 1.8MB 25 需要积分: 1
立即下载

资源介绍:

使用google地图的反向地址解析功能,提供一个经纬度得到对应地址,或者给出模糊地址,得到经纬度,放在java后台代码中处理,这个使用的是Google的地理编码服务。一般而言数据量不大的情况使用是不限制的。按照Google官方说法是连续90天请求地理编码服务次数超过2000次就会受到限制,因此可以将这些解析好的地址放在Database中,这样可以避免重复请求同一个地址。
/* * System Abbrev £º * system Name : * Component No £º * Component Name£º * File name £ºGoogleGeocoderUtil.java * Author £ºPeter.Qiu * Date £º2014-9-18 * Description : */ /* Updation record 1£º * Updation date : 2014-9-18 * Updator : Peter.Qiu * Trace No: * Updation No: * Updation Content: */ package com.qiuzhping.google; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.net.URLEncoder; import net.sf.json.JSONObject; import org.apache.log4j.Logger; import com.qiuzhping.google.beans.GoogleGeocodeJSONBean; /** * * type :1-->address 2-->latlng * * * @author Peter.Qiu * @version [Version NO, 2014-9-18] * @see [Related classes/methods] * @since [product/module version] */ public final class GoogleGeocoderUtil { public static final int ADDRESS = 1; public static final int LATLNG = 2; private final String GOOGLEAPIURL="http://maps.googleapis.com/maps/api/geocode/json?language=en&sensor=true"; private Logger log = Logger.getLogger(GoogleGeocoderUtil.class.getName()); private int type ;//1-->address 2-->latlng public int getType() { return type; } public void setType(int type) { this.type = type; } private static GoogleGeocoderUtil instance; public static GoogleGeocoderUtil getInstance() { if(instance == null){ instance = new GoogleGeocoderUtil(); } return instance; } /** * 2014-9-18 * * @author Peter.Qiu * @param address * @return * @return GoogleGeocodeJSONBean [Return type description] * @throws Exception * @exception throws [Exception] [Exception description] * @see [Related classes#Related methods#Related properties] */ public GoogleGeocodeJSONBean geocodeByAddress(String address) throws Exception{ if(address == null || address.equals("")){ return null; } log.info("geocode By Address : "+address); log.info("Start geocode"); GoogleGeocodeJSONBean bean = null; BufferedReader in= null; HttpURLConnection httpConn = null; try { log.info("Start open url"); String urlPath = GOOGLEAPIURL+"&address="+URLEncoder.encode(address,"UTF-8");; if(this.getType() == LATLNG){ urlPath = GOOGLEAPIURL+"&latlng="+address; } log.info("url : "+urlPath); URL url = new URL(urlPath); httpConn = (HttpURLConnection) url.openConnection(); log.info("End open url"); httpConn.setDoInput(true); in = new BufferedReader(new InputStreamReader(httpConn.getInputStream(),"UTF-8")); String line; String result=""; while ((line = in.readLine()) != null) { result += line; } in.close(); //httpConn.disconnect(); JSONObject jsonObject = JSONObject.fromObject( result ); bean = (GoogleGeocodeJSONBean) JSONObject.toBean( jsonObject, GoogleGeocodeJSONBean.class ); if(bean != null && bean.status.equalsIgnoreCase("ok") && bean.results != null && bean.results[0].geometry.getLocation() != null){ log.info("Start display Geocode info"); log.info("Formatted Address :" + bean.results[0].getFormatted_address()); log.info("geometry Location : " + bean.results[0].geometry.getLocation().getLat() + ","+bean.results[0].geometry.getLocation().getLng()); log.info("End display Geocode info"); } log.info("End geocode"); return bean; } catch (MalformedURLException e) { log.error(e); throw e; } catch (IOException e) { log.error(e); throw e; } finally { if (in != null) { try { in.close(); } catch (IOException e) { log.error(e); throw e; } } if (httpConn != null) { httpConn.disconnect(); } } } public String getGoogleLongitudeDimensions(GoogleGeocodeJSONBean googleBean) throws IOException{ if (googleBean != null && googleBean.status.equalsIgnoreCase("ok") && googleBean.results[0] != null && googleBean.results[0].formatted_address != null && googleBean.results[0].getGeometry().location != null && googleBean.results[0].getGeometry().location.getLat() != null && googleBean.results[0].getGeometry().location.getLng() != null) { String formatted_Address = googleBean.results[0].formatted_address; String location = googleBean.results[0].getGeometry().location.getLat()+","+googleBean.results[0].getGeometry().location.getLng(); return formatted_Address.trim()+"|"+location; } return null; } /** * 2014-9-18 * * @author Peter.Qiu * @param args [Parameters description] * @return void [Return type description] * @throws Exception * @exception throws [Exception] [Exception description] * @see [Related classes#Related methods#Related properties] */ public static void main(String[] args) throws Exception { try { getInstance().setType(2); GoogleGeocodeJSONBean bean = getInstance().geocodeByAddress("39.90403,116.407526"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }

资源文件列表:

GoogleMaps.zip 大约有47个文件
  1. GoogleMaps/
  2. GoogleMaps/.classpath 970B
  3. GoogleMaps/.project 386B
  4. GoogleMaps/.settings/
  5. GoogleMaps/.settings/org.eclipse.jdt.core.prefs 598B
  6. GoogleMaps/bin/
  7. GoogleMaps/bin/com/
  8. GoogleMaps/bin/com/qiuzhping/
  9. GoogleMaps/bin/com/qiuzhping/google/
  10. GoogleMaps/bin/com/qiuzhping/google/beans/
  11. GoogleMaps/bin/com/qiuzhping/google/beans/AddressComponents.class 1.02KB
  12. GoogleMaps/bin/com/qiuzhping/google/beans/Bounds.class 951B
  13. GoogleMaps/bin/com/qiuzhping/google/beans/Geometry.class 1.5KB
  14. GoogleMaps/bin/com/qiuzhping/google/beans/GoogleGeocodeJSONBean.class 918B
  15. GoogleMaps/bin/com/qiuzhping/google/beans/Location.class 733B
  16. GoogleMaps/bin/com/qiuzhping/google/beans/NorthEast.class 736B
  17. GoogleMaps/bin/com/qiuzhping/google/beans/Results.class 1.5KB
  18. GoogleMaps/bin/com/qiuzhping/google/beans/SouthWest.class 736B
  19. GoogleMaps/bin/com/qiuzhping/google/beans/ViewPoint.class 960B
  20. GoogleMaps/bin/com/qiuzhping/google/GoogleGeocoderUtil.class 5.66KB
  21. GoogleMaps/bin/log4j.properties 1.08KB
  22. GoogleMaps/libs/
  23. GoogleMaps/libs/commons-beanutils-1.7.0.jar 184.25KB
  24. GoogleMaps/libs/commons-collections-3.2.1.jar 561.9KB
  25. GoogleMaps/libs/commons-httpclient-3.1.jar 297.85KB
  26. GoogleMaps/libs/commons-lang-2.3.jar 239.53KB
  27. GoogleMaps/libs/commons-logging-1.1.1.jar 59.42KB
  28. GoogleMaps/libs/ezmorph-1.0.3.jar 76KB
  29. GoogleMaps/libs/json-lib-2.2.3-jdk15.jar 145.01KB
  30. GoogleMaps/libs/log4j-1.2.15.jar 382.65KB
  31. GoogleMaps/libs/log4jdbc4-1.2.jar 63.4KB
  32. GoogleMaps/src/
  33. GoogleMaps/src/com/
  34. GoogleMaps/src/com/qiuzhping/
  35. GoogleMaps/src/com/qiuzhping/google/
  36. GoogleMaps/src/com/qiuzhping/google/beans/
  37. GoogleMaps/src/com/qiuzhping/google/beans/AddressComponents.java 827B
  38. GoogleMaps/src/com/qiuzhping/google/beans/Bounds.java 669B
  39. GoogleMaps/src/com/qiuzhping/google/beans/Geometry.java 1005B
  40. GoogleMaps/src/com/qiuzhping/google/beans/GoogleGeocodeJSONBean.java 2.6KB
  41. GoogleMaps/src/com/qiuzhping/google/beans/Location.java 575B
  42. GoogleMaps/src/com/qiuzhping/google/beans/NorthEast.java 568B
  43. GoogleMaps/src/com/qiuzhping/google/beans/Results.java 1.12KB
  44. GoogleMaps/src/com/qiuzhping/google/beans/SouthWest.java 571B
  45. GoogleMaps/src/com/qiuzhping/google/beans/ViewPoint.java 677B
  46. GoogleMaps/src/com/qiuzhping/google/GoogleGeocoderUtil.java 5.4KB
  47. GoogleMaps/src/log4j.properties 1.08KB
0评论
提交 加载更多评论
其他资源 NET反编译工具
很强大的反编译工具,我后弄到的几个很好用的DLL,我都反编译,并弄出源码了,为我省了不少工夫啊,反编译出来的除了定义的变量名不一样外,其余的简直是一模一样。围绕它开发的插件也很多,用着真是开心!我还找到一个插件可以把源码导出到文件!更是爽!不过这个软件还不支持Unicode ,需要自己写一个转化程序,两个搭配起来用极爽!
PrettyGoodSplashScreenCode
用C#做的好看漂亮的程序启动界面,简单实用
Keil 找不到编译器 Missing:Complier Version5 的解决方法
arm complier v5.06
KITTI数据集可视化源码,对应教程为:https://blog.csdn.net/cg129054036/article/details/119516704
KITTI数据集可视化教程,教程:https://blog.csdn.net/cg129054036/article/details/119516704
Java互联网实时聊天系统源码.zip
Java互联网实时聊天系统源码.zip
usb_driver.zip
Android usb_driver ,解决设备端口不对, adb fastboot 无法连接问题
ActiveAndroid
ActiveAndroid 是轻量级持久性框架,简化了与SQLite数据库操作。
一个C++做MYSQL开发的精简开发包
一个C++做MYSQL开发的精简开发包