java 程序 用高德地图API 通过详细地址获得经纬度

AngelWings 2014-12-30 02:16:09
在一个java的接口中开发一个经纬度的查询,通过数据库获得的地址去查询该地址的经纬度。
百度了发现都是百度地图和谷歌地图的例子,请问有高德地图的例子吗?

请大神赐教,高分送上。
...全文
15798 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
jeasonxiao28 2016-05-06
  • 打赏
  • 举报
回复
private static String KEY = "aa4a48297242d22d2b3fd6eddfe62217"; private static Pattern pattern = Pattern.compile("\"location\":\"(\\d+\\.\\d+),(\\d+\\.\\d+)\""); public static double[] addressToGPS(String address) { try { String url = String .format("http://restapi.amap.com/v3/geocode/geo?&s=rsv3&address=%s&key=%s", address, KEY); URL myURL = null; URLConnection httpsConn = null; try { myURL = new URL(url); } catch (MalformedURLException e) { e.printStackTrace(); } InputStreamReader insr = null; BufferedReader br = null; httpsConn = (URLConnection) myURL.openConnection();// 不使用代理 if (httpsConn != null) { insr = new InputStreamReader( httpsConn.getInputStream(), "UTF-8"); br = new BufferedReader(insr); String data = ""; String line = null; while((line= br.readLine())!=null){ data+=line; } Matcher matcher = pattern.matcher(data); if (matcher.find() && matcher.groupCount() == 2) { double[] gps = new double[2]; gps[0] = Double.valueOf(matcher.group(1)); gps[1] = Double.valueOf(matcher.group(2)); return gps; } } }catch (Exception e) { e.printStackTrace(); return null; } return null; } public static void main(String[] args) { double [] data = AMap.addressToGPS("广东省"); System.out.println("经度:"+data[0]); System.out.println("纬度:"+data[1]); }
wwwmaocom 2015-05-04
  • 打赏
  • 举报
回复
引用 6 楼 baidu_27235609 的回复:
String addressStr = "http://restapi.amap.com/v3/geocode/geo?key=9a491a13997579f985c98165bb68d127&s=rsv3&city=028&address="; String getAddress = HttpUtils.get(addressStr + UrlEncoded.encodeString(address)); JSONObject object = JSONObject.parseObject(getAddress); JSONArray geocodes = object.getJSONArray("geocodes"); ExcelDetails details = ExcelDetails.dao.findById(id); if (geocodes.size() == 0) { details.set("status", 0); } else if (geocodes.size() == 1) { JSONObject trueAddress = geocodes.getJSONObject(0); String location = trueAddress.getString("location"); String lngX = location.split(",")[0]; String latY = location.split(",")[1]; } else { }
这个s=rsv3字段是什么意思?这个是官网的吗?
baidu_27235609 2015-04-08
  • 打赏
  • 举报
回复
String addressStr = "http://restapi.amap.com/v3/geocode/geo?key=9a491a13997579f985c98165bb68d127&s=rsv3&city=028&address="; String getAddress = HttpUtils.get(addressStr + UrlEncoded.encodeString(address)); JSONObject object = JSONObject.parseObject(getAddress); JSONArray geocodes = object.getJSONArray("geocodes"); ExcelDetails details = ExcelDetails.dao.findById(id); if (geocodes.size() == 0) { details.set("status", 0); } else if (geocodes.size() == 1) { JSONObject trueAddress = geocodes.getJSONObject(0); String location = trueAddress.getString("location"); String lngX = location.split(",")[0]; String latY = location.split(",")[1]; } else { }
  • 打赏
  • 举报
回复
同求,这两天看了彩云天气,也想弄弄...求高德地图api的例子
liguangwen86 2014-12-31
  • 打赏
  • 举报
回复
给你找了一下官网API 地址:http://lbs.amap.com/yuntu/reference/cloudsearch/ 请求示例:

http://yuntuapi.amap.com/datasearch/local?tableid=52b155b6e4b0bc61deeb7629&city=北京市&keywords= &filter=type:写字楼&limit=50&page=1&key=<用户key>     //搜索存储在云图数据表中的北京市的写字楼,返回第一页数据
示例返回结果:

{ 
  "info": "OK", 
  "status": 1, 
  "count": 2, 
  "datas": [ 
   { 
    "_id": "295", 
    "_name": "方恒国际", 
    "_location": "116.481471, 39.990471", 
    "_address": "北京市朝阳区阜通东大街18号", 
    "star": 4, 
    "rent":7.5, 
    "_createtime": "2013-12-19 17:23:44", 
    "_updatetime": "2013-12-19 17:23:44", 
   }, 
  { 
    "_id": "355", 
    "_name": "国际竹藤大厦", 
    "_location": "116.479894, 39.988999 ", 
    "_address": "北京市朝阳区望京阜通东大街8号", 
    "star": 4, 
    "rent":7, 
    "_createtime": "2013-12-19 17:19:05", 
    "_updatetime": "2013-12-19 17:19:05", 
  ] 
}
AngelWings 2014-12-31
  • 打赏
  • 举报
回复
麻烦大侠们给个例子,谢谢!
Runner6587 2014-12-31
  • 打赏
  • 举报
回复
官网上应该都有例子吧?
shoulders 2014-12-30
  • 打赏
  • 举报
回复
把问题关了,几本没人能回到这样的问题。

67,550

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧