根据经纬度确定行政区域_使用高德地图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 levelMap = new HashMap(){{//高德地图的省市区级别

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

//数据库存入操作

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;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值