码迷,mamicode.com
首页 > Windows程序 > 详细

使用高德地图api导入行政区域及经纬度

时间:2016-06-02 13:01:03      阅读:4592      评论:0      收藏:0      [点我收藏+]

标签:

  高德地图提供了行政区域及经纬度查询api

  参考如下链接

   高德地图行政区域api

具体实现代码如下

 


package com.test;


import java.util.HashMap;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;

import jvc.util.DBUtils;
import jvc.util.NetUtils;
import jvc.util.db.Insert;

public class Test {

static Map<String, String> levelMap = new HashMap<String, String>(){{//高德地图的省市区级别
this.put("province", "1");
this.put("city", "2");
this.put("district", "3");
this.put("biz_area", "4");
}};
public static void main(String[] args) throws Exception {

String str = NetUtils.getHtmlSource("http://restapi.amap.com/v3/config/district?keywords=新沟&level=district&subdistrict=3&key=053a406aad6f5afd49afd82a64a4e034",6000000,"utf-8");
JSONObject json = new JSONObject(str) ;
JSONArray ja = null;

judge(json.getJSONArray("districts"),"0");
}

public static void judge(JSONArray ja,String purl) throws Exception{

for(int i = 0 ; i <ja.length();i++){

//数据库存入操作
String id = insert(ja.getJSONObject(i), purl);

//判断是否递归
JSONArray cja = ja.getJSONObject(i).getJSONArray("districts");
if(cja.length() > 0)
judge(cja, id);
}
}

/**
*
* @param json 要存入的地区
* @param purl 上级区域
* @return
* @throws Exception
*/
public static String insert(JSONObject json,String purl) throws Exception{

Insert insert = new Insert("ED_CusStation");
String[] center = json.getString("center").split(",");
String id = DBUtils.getSerialNo("ED_CusStation")+"";
insert.setValue("longitude", center[0]);
insert.setValue("latitude", center[1]);
insert.setValue("sename", json.getString("name"));
insert.setValue("sename", json.getString("name"));
insert.setValue("purl",purl );
insert.setValue("locationStationId", id);
insert.setValue("level", levelMap.get(json.get("level")));
insert.execute();
return id;

}


}

 

使用高德地图api导入行政区域及经纬度

标签:

原文地址:http://www.cnblogs.com/max1ao/p/5552323.html

(2)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!