标签:
1 先上坐标取到的值:
获取到的坐标部分如下:
‘北京市‘:[116.39564503788,39.92998577808],
‘天津市‘:[117.21081309155,39.14392990331],
‘上海市‘:[121.48789948569,31.249161710015],
‘重庆市‘:[106.53063501341,29.544606108886],
‘合肥市‘:[117.28269909168,31.866942260687],
‘芜湖市‘:[118.38410842323,31.366019787543],
‘蚌埠市‘:[117.35707986588,32.929498906698],
‘淮南市‘:[117.01863886329,32.642811823748],
‘马鞍山市‘:[118.51588184662,31.68852815888],
‘淮北市‘:[116.79144742863,33.960023305364],
‘铜陵市‘:[117.81942872881,30.940929694666],
‘安庆市‘:[117.05873877211,30.537897817381],
‘黄山市‘:[118.293569632,29.734434856163],
‘滁州市‘:[118.32457035098,32.317350595384],
‘阜阳市‘:[115.82093225905,32.90121133057],
‘宿州市‘:[116.98869241183,33.636772385781],
‘六安市‘:[116.50525268298,31.755558355198],
‘亳州市‘:[115.78792824512,33.871210565302],
‘池州市‘:[117.49447677159,30.660019248161],
‘宣城市‘:[118.75209631098,30.951642354296],
‘福州市‘:[119.33022110713,26.047125496573],
‘厦门市‘:[118.10388604566,24.489230612469],
‘莆田市‘:[119.07773096396,25.448450136734],
‘三明市‘:[117.64219393404,26.270835279362],
‘泉州市‘:[118.60036234323,24.901652383991],
‘漳州市‘:[117.67620467895,24.517064779808],
‘南平市‘:[118.18188294866,26.643626474198],
‘龙岩市‘:[117.01799673877,25.078685433515],
‘宁德市‘:[119.54208214972,26.656527419159],
‘广州市‘:[113.30764967515,23.120049102076],
‘韶关市‘:[113.59446110744,24.802960311892],
‘深圳市‘:[114.02597365732,22.546053546205],
‘珠海市‘:[113.56244702619,22.256914646126],
‘汕头市‘:[116.72865028834,23.383908453269],
‘佛山市‘:[113.13402563539,23.035094840514],
‘江门市‘:[113.07812534115,22.575116783451],
‘湛江市‘:[110.36506726285,21.257463103764],
‘茂名市‘:[110.93124533068,21.668225718822],
‘肇庆市‘:[112.47965336992,23.078663282929],
‘惠州市‘:[114.41065807997,23.113539852408],
‘梅州市‘:[116.12640309837,24.304570606031],
‘汕尾市‘:[115.3729242894,22.778730500164],
‘河源市‘:[114.71372147587,23.757250850469],
‘阳江市‘:[111.97700975587,21.871517304519],
‘清远市‘:[113.04077334891,23.698468550422],
‘潮州市‘:[116.63007599086,23.661811676517],
‘揭阳市‘:[116.37950085538,23.547999466926],
‘云浮市‘:[112.05094595865,22.937975685537],
‘贵阳市‘:[106.70917709618,26.629906741441],
‘六盘水市‘:[104.85208676007,26.591866060319],
‘遵义市‘:[106.93126031648,27.699961377076],
‘安顺市‘:[105.92826996576,26.228594577737],
‘毕节市‘:[105.33332337117,27.408562131331],
‘铜仁市‘:[109.16855802826,27.674902690624],
‘黔西南布依族苗族自治州‘:[104.90055779825,25.095148055927],
‘黔东南苗族侗族自治州‘:[107.98535257274,26.583991766542],
‘黔南布依族苗族自治州‘:[107.52320511006,26.264535997442],
‘海口市‘:[110.33080184834,20.022071276952],
‘三亚市‘:[109.52277128136,18.257775914897],
‘三沙市‘:[108.52277128136,17.257775914897],
4个直辖市是手动添加上去的
2 坐标系
坐标系相关的知识;上面获取到的是百度坐标系 需要转换的如下方法: 网盘地址:http://pan.baidu.com/s/1huRBw 感兴趣的可以点击链接下载!
国家规定,军队,国家机关的涉密数据。。。。。。不能使用WGS84坐标系,大家开发项目请注意。
比较专业的坐标相互之间的转换如下:
/*
* Project Name:Hecha
* File Name:CommonCooder.java
* Package Name:com.example.hecha
* Date:2014-12-5下午2:39:09
* Copyright (c) 2014, chinhiyoshi@163.com 陈飞 Rights Reserved.
*
*/
package com.example.hecha;
/*
* ClassName:CommonCooder
* Function: ADD FUNCTION.
* Reason: ADD REASON.
* Date: 2014-12-5 下午2:39:09
* @author cf
* @version
* @since JDK 1.6
*/
public class CommonCooder {
static double pi = 3.14159265358979324;
static double a = 6378245.0;
static double ee = 0.00669342162296594323;
static double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
//WGS84坐标系转成BD09
public static String WGS84ToBd09(double gg_lat, double gg_lon) {
String[] redbstring = transform(gg_lat, gg_lon).split(",");// WGS84 ===>GCj_02
gg_lon = Double.parseDouble(redbstring[0]);
gg_lat = Double.parseDouble(redbstring[1]);
// gcj-02 to bd09
double bd_lat;
double bd_lon;
double x = gg_lon, y = gg_lat;
double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
bd_lon = z * Math.cos(theta) + 0.0065;
bd_lat = z * Math.sin(theta) + 0.006;
System.out.println("BD:" + bd_lat + "," + bd_lon);
return bd_lon + "," + bd_lat;
}
// WGS84 ======> GCj_02
private static String transform(double wgLat, double wgLon) {
double mgLat;
double mgLon;
String resultString = null;
if (outOfChina(wgLat, wgLon)) {
resultString = wgLon + "," + wgLat;
mgLat = wgLat;
mgLon = wgLon;
return resultString;
}
double dLat = transformLat(wgLon - 105.0, wgLat - 35.0);
double dLon = transformLon(wgLon - 105.0, wgLat - 35.0);
double radLat = wgLat / 180.0 * pi;
double magic = Math.sin(radLat);
magic = 1 - ee * magic * magic;
double sqrtMagic = Math.sqrt(magic);
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);
dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi);
mgLat = wgLat + dLat;
mgLon = wgLon + dLon;
return mgLon + "," + mgLat;
}
private static boolean outOfChina(double lat, double lon) {
if (lon < 72.004 || lon > 137.8347)
return true;
if (lat < 0.8293 || lat > 55.8271)
return true;
return false;
}
private static double transformLat(double x, double y) {
double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y+ 0.2 * Math.sqrt(Math.abs(x));
ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(y * pi) + 40.0 * Math.sin(y / 3.0 * pi)) * 2.0 / 3.0;
ret += (160.0 * Math.sin(y / 12.0 * pi) + 320 * Math.sin(y * pi / 30.0)) * 2.0 / 3.0;
return ret;
}
private static double transformLon(double x, double y) {
double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1* Math.sqrt(Math.abs(x));
ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(x * pi) + 40.0 * Math.sin(x / 3.0 * pi)) * 2.0 / 3.0;
ret += (150.0 * Math.sin(x / 12.0 * pi) + 300.0 * Math.sin(x / 30.0
* pi)) * 2.0 / 3.0;
return ret;
}
}
3 获取坐标值的方法
http://api.map.baidu.com/geocoder/v2/?ak=你在百度申请的KEY&output=json&address=城市名称&city=XX省 【百度的获取地址】
上一篇提到了怎么获取全国的省市县镇乡村。。。。。想了解的请点击 【http://www.cnblogs.com/chinhi/p/jsoupgetdata.html】 不好意思。。。连接给错了 不过也可以点击
[亮一下你的眼睛]
有了数据如下:
然后数据库查询一下:【select name from tab where name is not null and name !=‘‘】
读取到list集合 然后for循环执行百度坐标即可。。。。。。。。。。。。。。。。。。。。。。。。。
然后就去到了最上面的地理坐标数据,你就可以猥琐欲为了
哈哈 !
另外附上北斗坐标系的转换。。。。。。。。。。。。。。。。。http://pan.baidu.com/s/1dDdkW7J
要我能提供的源码,请在里面发邮箱获取。。。。。。
以上!
获取全国市以及地理坐标,各大坐标系北斗,百度,WGS-84坐标系的转换
标签:
原文地址:http://www.cnblogs.com/kanjidesu/p/getcooderv.html