百度高德谷歌地图与大地坐标系相互转换
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* @Author Zhanglele
* @Date 2020/11/13 20:14
*/
public class ChinaMapUtil {
private static List<Point[]> chinaPolygon = new ArrayList<>();
private static List<Point[]> taiWanPolygon = new ArrayList<>();
private static List<Point[]> xiangGangPolygon = new ArrayList<>();
public ChinaMapUtil() {
}
public static boolean isInsideChina(double lat, double lng) {
return isInsideArea(lat, lng, chinaPolygon);
}
public static boolean isInsideTaiWan(double lat, double lng) {
return isInsideArea(lat, lng, taiWanPolygon);
}
public static boolean isInsideXiangGang(double lat, double lng) {
return isInsideArea(lat, lng, xiangGangPolygon);
}
public static boolean isInsideArea(double lat, double lng, List<Point[]> points) {
Iterator var5 = points.iterator();
boolean inside;
do {
if (!var5.hasNext()) {
return false;
}
Point[] poly = (Point[])var5.next();
inside = false;
Point prePoint = poly[0];
for(int index = 1; index < poly.length; ++index) {
Point nextPoint = poly[index];
if (lng > Math.min(prePoint.y, nextPoint.y) && lng <= Math.max(prePoint.y, nextPoint.y) && lat <= Math.max(prePoint.x, nextPoint.x) && prePoint.y != nextPoint.y) {
double xinters = (lng - prePoint.y) * (nextPoint.x - prePoint.x) / (nextPoint.y - prePoint.y) + prePoint.x;
if (prePoint.x == nextPoint.x || lat <= xinters) {
inside ^= true;
}
}
prePoint = nextPoint;
}
} while(!inside);
return true;
}
static {
xiangGangPolygon.add(new Point[]{new Point(22.5288D, 114.3092D), new Point(22.5307D, 114.2902D), new Point(22.5526D, 114.2952D), new Point(22.5474D, 114.3223D), new Point(22.5442D, 114.2998D), new Point(22.5288D, 114.3092D)});
xiangGangPolygon.add(new Point[]{new Point(22.3393D, 114.3276D), new Point(22.3479D, 114.3079D), new Point(22.3647D, 114.3101D), new Point(22.3779D, 114.3053D), new Point(22.3762D, 114.3224D), new Point(22.3393D, 114.3276D)});
xiangGangPolygon.add(new Point[]{new Point(22.3502D, 114.3011D), new Point(22.3645D, 114.2915D), new Point(22.3731D, 114.2983D), new Point(22.3717D, 114.3013D), new Point(22.3632D, 114.3029D), new Point(22.3502D, 114.3011D)});
xiangGangPolygon.add(new Point[]{new Point(22.2138D, 114.1425D), new Point(22.2019D, 114.134D), new Point(22.2067D, 114.1661D), new Point(22.1941D, 114.1489D), new Point(22.1791D, 114.1558D), new Point(22.1778D, 114.1204D), new Point(22.2116D, 114.1247D), new Point(22.2085D, 114.1073D), new Point(22.2322D, 114.1109D), new Point(22.2367D, 114.1274D), new Point(22.2138D, 114.1425D)});
xiangGangPolygon.add(new Point[]{new Point(22.54D, 114.2326D), new Point(22.5385D, 114.2238D), new Point(22.5243D, 114.2144D), new Point(22.5238D, 114.2184D), new Point(22.5256D, 114.2231D), new Point(22.5289D, 114.226D), new Point(22.528D, 114.2321D), new Point(22.5473D, 114.247D), new Point(22.5473D, 114.2619D), new Point(22.5462D, 114.2657D), new Point(22.5423D, 114.2625D), new Point(22.5385D, 114.2645D), new Point(22.5329D, 114.2733D), new Point(22.5241D, 114.2686D), new Point(22.5224D, 114.2916D), new Point(22.5086D, 114.2833D), new Point(22.4973D, 114.3089D), new Point(22.5055D, 114.3425D), new Point(22.4455D, 114.2532D), new Point(22.4666D, 114.2341D), new Point(22.4656D, 114.2186D), new Point(22.45D, 114.2222D), new Point(22.4517D, 114.2389D), new Point(22.4439D, 114.22D), new Point(22.4511D, 114.2071D), new Point(22.4372D, 114.2053D), new Point(22.4266D, 114.2243D), new Point(22.4353D, 114.2776D), new Point(22.4752D, 114.3178D), new Point(22.4626D, 114.3386D), new Point(22.4775D, 114.347D), new Point(22.4377D, 114.3472D), new Point(22.4584D, 114.3689D), new Point(22.4367D, 114.3757D), new Point(22.434D, 114.4058D), new Point(22.4207D, 114.4054D), new Point(22.4106D, 114.4119D), new Point(22.4114D, 114.3856D), new Point(22.365D, 114.3969D), new Point(22.3477D, 114.3655D), new Point(22.3325D, 114.3627D), new Point(22.3486D, 114.3414D), new Point(22.3732D, 114.338D), new Point(22.3891D, 114.3209D), new Point(22.3881D, 114.2842D), new Point(22.3287D, 114.2784D), new Point(22.2946D, 114.3178D), new Point(22.2569D, 114.3044D), new Point(22.2597D, 114.2763D), new Point(22.2944D, 114.265D), new Point(22.283D, 114.2504D), new Point(22.2587D, 114.2631D), new Point(22.2011D, 114.266D), new Point(22.2139D, 114.2383D), new Point(22.191D, 114.2176D), new Point(22.2326D, 114.2001D), new Point(22.2396D, 114.186D), new Point(22.2263D, 114.1656D), new Point(22.2723D, 114.1205D), new Point(22.3033D, 114.1439D), new Point(22.3296D, 114.0783D), new Point(22.2996D, 114.0341D), new Point(22.2626D, 114.0292D), new Point(22.2673D, 114.005D), new Point(22.2501D, 114.0179D), new Point(22.2394D, 114.0047D), new Point(22.2287D, 114.0265D), new Point(22.2119D, 114.0093D), new Point(22.2066D, 113.9917D), new Point(22.2308D, 113.9757D), new Point(22.205D, 113.9356D), new Point(22.2162D, 113.895D), new Point(22.1912D, 113.8494D), new Point(22.2292D, 113.8435D), new Point(22.282D, 113.8971D), new Point(22.3088D, 113.8981D), new Point(22.3213D, 113.9511D), new Point(22.2984D, 113.9553D), new Point(22.3451D, 114.0263D), new Point(22.3661D, 113.9799D), new Point(22.3548D, 113.9476D), new Point(22.3652D, 113.9238D), new Point(22.4027D, 113.9052D), new Point(22.4182D, 113.9183D), new Point(22.4568D, 113.9777D), new Point(22.4902D, 113.9998D), new Point(22.4805D, 114.025D), new Point(22.5031D, 114.0292D), new Point(22.5007D, 114.06D), new Point(22.5341D, 114.0953D), new Point(22.5391D, 114.1531D), new Point(22.5585D, 114.1665D), new Point(22.54D, 114.2326D)});
chinaPolygon.add(new Point[]{new Point(27.32083D, 88.91693D), new Point(27.54243D, 88.76464D), new Point(28.00805D, 88.83575D), new Point(28.1168D, 88.62435D), new Point(27.86605D, 88.14279D), new Point(27.82305D, 87.19275D), new Point(28.11166D, 86.69527D), new Point(27.90888D, 86.45137D), new Point(28.15805D, 86.19769D), new Point(27.88625D, 86.0054D), new Point(28.27916D, 85.72137D), new Point(28.30666D, 85.11095D), new Point(28.59104D, 85.19518D), new Point(28.54444D, 84.84665D), new Point(28.73402D, 84.48623D), new Point(29.26097D, 84.11651D), new Point(29.18902D, 83.5479D), new Point(29.63166D, 83.19109D), new Point(30.06923D, 82.17525D), new Point(30.33444D, 82.11123D), new Point(30.385D, 81.42623D), new Point(30.01194D, 81.23221D), new Point(30.20435D, 81.02536D), new Point(30.57552D, 80.207D), new Point(30.73374D, 80.25423D), new Point(30.96583D, 79.86304D), new Point(30.95708D, 79.55429D), new Point(31.43729D, 79.08082D), new Point(31.30895D, 78.76825D), new Point(31.96847D, 78.77075D), new Point(32.24304D, 78.47594D), new Point(32.5561D, 78.40595D), new Point(32.63902D, 78.74623D), new Point(32.35083D, 78.9711D), new Point(32.75666D, 79.52874D), new Point(33.09944D, 79.37511D), new Point(33.42863D, 78.93623D), new Point(33.52041D, 78.81387D), new Point(34.06833D, 78.73581D), new Point(34.35001D, 78.98535D), new Point(34.6118D, 78.33707D), new Point(35.28069D, 78.02305D), new Point(35.49902D, 78.0718D), new Point(35.50133D, 77.82393D), new Point(35.6125D, 76.89526D), new Point(35.90665D, 76.55304D), new Point(35.81458D, 76.18061D), new Point(36.07082D, 75.92887D), new Point(36.23751D, 76.04166D), new Point(36.66343D, 75.85984D), new Point(36.73169D, 75.45179D), new Point(36.91156D, 75.39902D), new Point(36.99719D, 75.14787D), new Point(37.02782D, 74.56543D), new Point(37.17D, 74.39089D), new Point(37.23733D, 74.91574D), new Point(37.40659D, 75.18748D), new Point(37.65243D, 74.9036D), new Point(38.47256D, 74.85442D), new Point(38.67438D, 74.35471D), new Point(38.61271D, 73.81401D), new Point(38.88653D, 73.70818D), new Point(38.97256D, 73.85235D), new Point(39.23569D, 73.62005D), new Point(39.45483D, 73.65569D), new Point(39.59965D, 73.95471D), new Point(39.76896D, 73.8429D), new Point(40.04202D, 73.99096D), new Point(40.32792D, 74.88089D), new Point(40.51723D, 74.8588D), new Point(40.45042D, 75.23394D), new Point(40.64452D, 75.58284D), new Point(40.298D, 75.70374D), new Point(40.35324D, 76.3344D), new Point(41.01258D, 76.87067D), new Point(41.04079D, 78.08083D), new Point(41.39286D, 78.39554D), new Point(42.03954D, 80.24513D), new Point(42.19622D, 80.23402D), new Point(42.63245D, 80.15804D), new Point(42.81565D, 80.25796D), new Point(42.88545D, 80.57226D), new Point(43.02906D, 80.38405D), new Point(43.1683D, 80.81526D), new Point(44.11378D, 80.36887D), new Point(44.6358D, 80.38499D), new Point(44.73408D, 80.51589D), new Point(44.90282D, 79.87106D), new Point(45.3497D, 81.67928D), new Point(45.15748D, 81.94803D), new Point(45.13303D, 82.56638D), new Point(45.43581D, 82.64624D), new Point(45.5831D, 82.32179D), new Point(47.20061D, 83.03443D), new Point(46.97332D, 83.93026D), new Point(46.99361D, 84.67804D), new Point(46.8277D, 84.80318D), new Point(47.0591D, 85.52257D), new Point(47.26221D, 85.70139D), new Point(47.93721D, 85.53707D), new Point(48.39333D, 85.76596D), new Point(48.54277D, 86.59791D), new Point(49.1102D, 86.87602D), new Point(49.09262D, 87.34821D), new Point(49.17295D, 87.8407D), new Point(48.98304D, 87.89291D), new Point(48.88103D, 87.7611D), new Point(48.73499D, 88.05942D), new Point(48.56541D, 87.99194D), new Point(48.40582D, 88.51679D), new Point(48.21193D, 88.61179D), new Point(47.99374D, 89.08514D), new Point(47.88791D, 90.07096D), new Point(46.95221D, 90.9136D), new Point(46.57735D, 91.07027D), new Point(46.29694D, 90.92151D), new Point(46.01735D, 91.02651D), new Point(45.57972D, 90.68193D), new Point(45.25305D, 90.89694D), new Point(45.07729D, 91.56088D), new Point(44.95721D, 93.5547D), new Point(44.35499D, 94.71735D), new Point(44.29416D, 95.41061D), new Point(44.01937D, 95.34109D), new Point(43.99311D, 95.53339D), new Point(43.28388D, 95.87901D), new Point(42.73499D, 96.38206D), new Point(42.79583D, 97.1654D), new Point(42.57194D, 99.51012D), new Point(42.67707D, 100.8425D), new Point(42.50972D, 101.8147D), new Point(42.23333D, 102.0772D), new Point(41.88721D, 103.4164D), new Point(41.87721D, 104.5267D), new Point(41.67068D, 104.5237D), new Point(41.58666D, 105.0065D), new Point(42.46624D, 107.4758D), new Point(42.41114007095246D, 107.5686320861712D), new Point(42.69999D, 109.3107D), new Point(42.64576D, 110.1064D), new Point(43.31694D, 110.9897D), new Point(43.69221D, 111.9583D), new Point(44.37527D, 111.4214D), new Point(45.04944D, 111.873D), new Point(45.08055D, 112.4272D), new Point(44.8461D, 112.853D), new Point(44.74527D, 113.638D), new Point(45.38943D, 114.5453D), new Point(45.4586D, 115.7019D), new Point(45.72193D, 116.2104D), new Point(46.29583D, 116.5855D), new Point(46.41888D, 117.3755D), new Point(46.57069D, 117.425D), new Point(46.53645D, 117.8455D), new Point(46.73638D, 118.3147D), new Point(46.59895D, 119.7068D), new Point(46.71513D, 119.9315D), new Point(46.90221D, 119.9225D), new Point(47.66499D, 119.125D), new Point(47.99475D, 118.5393D), new Point(48.01125D, 117.8046D), new Point(47.65741D, 117.3827D), new Point(47.88805D, 116.8747D), new Point(47.87819D, 116.2624D), new Point(47.69186D, 115.9231D), new Point(47.91749D, 115.5944D), new Point(48.14353D, 115.5491D), new Point(48.25249D, 115.8358D), new Point(48.52055D, 115.8111D), new Point(49.83047D, 116.7114D), new Point(49.52058D, 117.8747D), new Point(49.92263D, 118.5746D), new Point(50.09631D, 119.321D), new Point(50.33028D, 119.36D), new Point(50.39027D, 119.1386D), new Point(51.62083D, 120.0641D), new Point(52.115D, 120.7767D), new Point(52.34423D, 120.6259D), new Point(52.54267D, 120.7122D), new Point(52.58805D, 120.0819D), new Point(52.76819D, 120.0314D), new Point(53.26374D, 120.8307D), new Point(53.54361D, 123.6147D), new Point(53.18832D, 124.4933D), new Point(53.05027D, 125.62D), new Point(52.8752D, 125.6573D), new Point(52.75722D, 126.0968D), new Point(52.5761D, 125.9943D), new Point(52.12694D, 126.555D), new Point(51.99437D, 126.4412D), new Point(51.38138D, 126.9139D), new Point(51.26555D, 126.8176D), new Point(51.31923D, 126.9689D), new Point(51.05825D, 126.9331D), new Point(50.74138D, 127.2919D), new Point(50.31472D, 127.334D), new Point(50.20856D, 127.5861D), new Point(49.80588D, 127.515D), new Point(49.58665D, 127.838D), new Point(49.58443D, 128.7119D), new Point(49.34676D, 129.1118D), new Point(49.4158D, 129.4902D), new Point(48.86464D, 130.2246D), new Point(48.86041D, 130.674D), new Point(48.60576D, 130.5236D), new Point(48.3268D, 130.824D), new Point(48.10839D, 130.6598D), new Point(47.68721D, 130.9922D), new Point(47.71027D, 132.5211D), new Point(48.09888D, 133.0827D), new Point(48.06888D, 133.4843D), new Point(48.39112D, 134.4153D), new Point(48.26713D, 134.7408D), new Point(47.99207D, 134.5576D), new Point(47.70027D, 134.7608D), new Point(47.32333D, 134.1825D), new Point(46.64017D, 133.9977D), new Point(46.47888D, 133.8472D), new Point(46.25363D, 133.9016D), new Point(45.82347D, 133.4761D), new Point(45.62458D, 133.4702D), new Point(45.45083D, 133.1491D), new Point(45.05694D, 133.0253D), new Point(45.34582D, 131.8684D), new Point(44.97388D, 131.4691D), new Point(44.83649D, 130.953D), new Point(44.05193D, 131.298D), new Point(43.53624D, 131.1912D), new Point(43.38958D, 131.3104D), new Point(42.91645D, 131.1285D), new Point(42.74485D, 130.4327D), new Point(42.42186D, 130.6044D), new Point(42.71416D, 130.2468D), new Point(42.88794D, 130.2514D), new Point(43.00457D, 129.9046D), new Point(42.43582D, 129.6955D), new Point(42.44624D, 129.3493D), new Point(42.02736D, 128.9269D), new Point(42.00124D, 128.0566D), new Point(41.58284D, 128.3002D), new Point(41.38124D, 128.1529D), new Point(41.47249D, 127.2708D), new Point(41.79222D, 126.9047D), new Point(41.61176D, 126.5661D), new Point(40.89694D, 126.0118D), new Point(40.47037D, 124.8851D), new Point(40.09362D, 124.3736D), new Point(39.82777D, 124.128D), new Point(39.67388D, 123.2167D), new Point(38.8611D, 121.6982D), new Point(38.51909D, 121.1873D), new Point(38.81221D, 121.0887D), new Point(39.87242D, 120.1264D), new Point(39.15693D, 118.9715D), new Point(38.38666D, 118.1722D), new Point(38.1529D, 118.8378D), new Point(37.83499D, 120.7371D), new Point(37.55256D, 122.6282D), new Point(37.41833D, 122.6814D), new Point(37.39624D, 123.0586D), new Point(37.20999D, 122.8872D), new Point(37.00027D, 122.9566D), new Point(36.52638D, 121.46D), new Point(36.14075D, 121.1956D), new Point(35.95943D, 120.7378D), new Point(34.88499D, 119.6761D), new Point(34.31145D, 120.7487D), new Point(32.97499D, 121.3858D), new Point(32.63889D, 121.3375D), new Point(32.42958D, 121.8348D), new Point(32.11333D, 121.9412D), new Point(32.02166D, 122.1066D), new Point(31.67833D, 122.3275D), new Point(31.30889D, 122.1681D), new Point(30.97986D, 122.3828D), new Point(30.85305D, 122.3469D), new Point(29.88211D, 122.6196D), new Point(29.58916D, 122.4744D), new Point(28.9359D, 121.9908D), new Point(28.72798D, 122.1113D), new Point(28.66993D, 121.9844D), new Point(28.34722D, 122.1417D), new Point(28.13889D, 121.8419D), new Point(27.87229D, 121.34D), new Point(27.59319D, 121.0812D), new Point(27.45083D, 121.1655D), new Point(27.20777D, 121.0075D), new Point(27.14764D, 120.9211D), new Point(26.89805D, 120.6332D), new Point(26.64465D, 120.828D), new Point(26.64888D, 120.8668D), new Point(26.79611D, 120.7879D), new Point(26.75625D, 120.5503D), new Point(26.44222D, 120.8204D), new Point(26.47388D, 120.5775D), new Point(26.33861D, 120.658D), new Point(26.36777D, 120.9489D), new Point(25.99694D, 120.4253D), new Point(26.14041D, 120.0975D), new Point(25.93788D, 120.354D), new Point(25.99069D, 120.7058D), new Point(25.67996D, 120.5807D), new Point(25.68222D, 120.4522D), new Point(25.35333D, 120.6454D), new Point(25.60649D, 120.3149D), new Point(25.42097D, 120.1053D), new Point(25.25319D, 120.3526D), new Point(25.17208D, 120.2726D), new Point(25.2426D, 119.8749D), new Point(24.97194D, 119.9866D), new Point(24.88291D, 119.5729D), new Point(24.75673D, 119.7631D), new Point(24.52861D, 119.5953D), new Point(24.53638D, 119.2397D), new Point(24.68194D, 119.1688D), new Point(24.44024D, 119.0199D), new Point(24.46019D, 118.7947D), new Point(24.25875D, 119.1237D), new Point(23.62437D, 118.1957D), new Point(23.65919D, 117.9179D), new Point(23.355D, 117.7603D), new Point(23.42024D, 117.5322D), new Point(23.23666D, 117.7871D), new Point(23.21083D, 117.5139D), new Point(22.93902D, 117.4817D), new Point(22.73916D, 116.7978D), new Point(22.88416D, 116.6403D), new Point(22.65889D, 116.5367D), new Point(22.80833D, 116.1614D), new Point(22.70277D, 115.8889D), new Point(22.53305D, 115.8722D), new Point(22.64027D, 115.718D), new Point(22.50423D, 115.6136D), new Point(22.42993D, 115.3885D), new Point(22.26056D, 115.2961D), new Point(21.94944D, 113.5648D), new Point(21.88701D, 113.5527D), new Point(21.87965D, 113.3868D), new Point(21.74069D, 113.2226D), new Point(21.7693D, 112.94D), new Point(21.46472D, 112.824D), new Point(21.70139D, 112.2819D), new Point(21.55139D, 111.9669D), new Point(21.51264D, 111.7832D), new Point(21.4268D, 111.644D), new Point(21.22528D, 111.0285D), new Point(21.21138D, 110.7328D), new Point(20.84083D, 110.8755D), new Point(20.64D, 110.8239D), new Point(20.48618D, 110.6274D), new Point(20.21611D, 110.2789D), new Point(20.2136D, 109.9244D), new Point(20.92416D, 109.6629D), new Point(21.44694D, 109.9411D), new Point(21.50569D, 109.6605D), new Point(21.49499D, 109.5344D), new Point(21.39666D, 109.1428D), new Point(21.61611D, 108.911D), new Point(21.59888D, 108.7403D), new Point(21.59014D, 108.5125D), new Point(21.51444D, 108.2447D), new Point(21.54241D, 107.99D), new Point(21.66694D, 107.7831D), new Point(21.60526D, 107.3627D), new Point(22.03083D, 106.6933D), new Point(22.45682D, 106.5517D), new Point(22.76389D, 106.7875D), new Point(22.86694D, 106.7029D), new Point(22.91253D, 105.8771D), new Point(23.32416D, 105.3587D), new Point(23.18027D, 104.9075D), new Point(22.81805D, 104.7319D), new Point(22.6875D, 104.3747D), new Point(22.79812D, 104.1113D), new Point(22.50387D, 103.9687D), new Point(22.78287D, 103.6538D), new Point(22.58436D, 103.5224D), new Point(22.79451D, 103.3337D), new Point(22.43652D, 103.0304D), new Point(22.77187D, 102.4744D), new Point(22.39629D, 102.1407D), new Point(22.49777D, 101.7415D), new Point(22.20916D, 101.5744D), new Point(21.83444D, 101.7653D), new Point(21.14451D, 101.786D), new Point(21.17687D, 101.2919D), new Point(21.57264D, 101.1482D), new Point(21.76903D, 101.099D), new Point(21.47694D, 100.6397D), new Point(21.43546D, 100.2057D), new Point(21.72555D, 99.97763D), new Point(22.05018D, 99.95741D), new Point(22.15592D, 99.16785D), new Point(22.93659D, 99.56484D), new Point(23.08204D, 99.5113D), new Point(23.18916D, 98.92747D), new Point(23.97076D, 98.67991D), new Point(24.16007D, 98.89073D), new Point(23.92999D, 97.54762D), new Point(24.26055D, 97.7593D), new Point(24.47666D, 97.54305D), new Point(24.73992D, 97.55255D), new Point(25.61527D, 98.19109D), new Point(25.56944D, 98.36137D), new Point(25.85597D, 98.7104D), new Point(26.12527D, 98.56944D), new Point(26.18472D, 98.73109D), new Point(26.79166D, 98.77777D), new Point(27.52972D, 98.69699D), new Point(27.6725D, 98.45888D), new Point(27.54014D, 98.31992D), new Point(28.14889D, 98.14499D), new Point(28.54652D, 97.55887D), new Point(28.22277D, 97.34888D), new Point(28.46749D, 96.65387D), new Point(28.35111D, 96.40193D), new Point(28.525D, 96.34027D), new Point(28.79569D, 96.61373D), new Point(29.05666D, 96.47083D), new Point(28.90138D, 96.17532D), new Point(29.05972D, 96.14888D), new Point(29.25757D, 96.39172D), new Point(29.46444D, 96.08315D), new Point(29.03527D, 95.38777D), new Point(29.33346D, 94.64751D), new Point(29.07348D, 94.23456D), new Point(28.6692D, 93.96172D), new Point(28.61876D, 93.35194D), new Point(28.3193D, 93.22205D), new Point(28.1419D, 92.71044D), new Point(27.86194D, 92.54498D), new Point(27.76472D, 91.65776D), new Point(27.945D, 91.66277D), new Point(28.08111D, 91.30138D), new Point(27.96999D, 91.08693D), new Point(28.07958D, 90.3765D), new Point(28.24257D, 90.38898D), new Point(28.32369D, 89.99819D), new Point(28.05777D, 89.48749D), new Point(27.32083D, 88.91693D)});
chinaPolygon.add(new Point[]{new Point(25.13474D, 121.4441D), new Point(25.28361D, 121.5632D), new Point(25.00722D, 122.0004D), new Point(24.85028D, 121.8182D), new Point(24.47638D, 121.8397D), new Point(23.0875D, 121.3556D), new Point(21.92791D, 120.7196D), new Point(22.31277D, 120.6103D), new Point(22.54044D, 120.3071D), new Point(23.04437D, 120.0539D), new Point(23.61708D, 120.1112D), new Point(25.00166D, 121.0017D), new Point(25.13474D, 121.4441D)});
chinaPolygon.add(new Point[]{new Point(19.52888D, 110.855D), new Point(19.16761D, 110.4832D), new Point(18.80083D, 110.5255D), new Point(18.3852D, 110.0503D), new Point(18.39152D, 109.7594D), new Point(18.19777D, 109.7036D), new Point(18.2258D, 109.4138D), new Point(18.50562D, 108.6871D), new Point(19.28028D, 108.6283D), new Point(19.76D, 109.2939D), new Point(19.7236D, 109.1653D), new Point(19.89972D, 109.2572D), new Point(19.82861D, 109.4658D), new Point(19.99389D, 109.6108D), new Point(20.13361D, 110.6655D), new Point(19.97861D, 110.9425D), new Point(19.63829D, 111.0215D), new Point(19.52888D, 110.855D), new Point(19.1D, 110.5D)});
chinaPolygon.add(new Point[]{new Point(31.80054D, 121.2039D), new Point(31.49972D, 121.8736D), new Point(31.53111D, 121.5464D), new Point(31.80054D, 121.2039D)});
taiWanPolygon.add(new Point[]{new Point(25.13474D, 121.4441D), new Point(25.28361D, 121.5632D), new Point(25.00722D, 122.0004D), new Point(24.85028D, 121.8182D), new Point(24.47638D, 121.8397D), new Point(23.0875D, 121.3556D), new Point(21.92791D, 120.7196D), new Point(22.31277D, 120.6103D), new Point(22.54044D, 120.3071D), new Point(23.04437D, 120.0539D), new Point(23.61708D, 120.1112D), new Point(25.00166D, 121.0017D), new Point(25.13474D, 121.4441D)});
}
}
class Point {
double x;
double y;
Point(double x, double y) {
this.x = x;
this.y = y;
}
}
package other;
/**
* @Author Zhanglele
* @Date 2020/11/13 20:09
*/
public class CoordinateFormatUtil {
public CoordinateFormatUtil() {
}
public static String format(float latOrLng) {
return String.format("%.6f", latOrLng);
}
public static String format(double latOrLng) {
return String.format("%.6f", latOrLng);
}
public static String format(float latOrLng, boolean isNegative) {
return isNegative && latOrLng > 9.0E-7F ? String.format("-%.6f", latOrLng) : format(latOrLng);
}
public static String format(double latOrLng, boolean isNegative) {
return isNegative && latOrLng > 9.0E-7D ? String.format("-%.6f", latOrLng) : format(latOrLng);
}
public static String format(String latOrLng) {
int dotIndex = latOrLng.indexOf(46);
int maxLength = latOrLng.length();
if (dotIndex >= 0 && maxLength > dotIndex + 7) {
maxLength = dotIndex + 7;
return latOrLng.substring(0, maxLength);
} else {
return latOrLng;
}
}
}
package other;
import java.util.Objects;
/**
* @Author Zhanglele
* @Date 2020/11/13 20:09
*/
public class GPSMapUtil {
static double pi = 3.141592653589793D;
static double a = 6378245.0D;
static double ee = 0.006693421622965943D;
public static void main(String[] args) {
String[] location = getWGSLocationByMapType("120.304414", "31.572099", 1);
String[] resultLocationByMapType = getResultLocationByMapType(location[0], location[1], 1);
System.out.println();
}
/**
* 将大地坐标系转化为对应地图的坐标系
*/
public static String[] getResultLocationByMapType(String lon, String lat, Integer mapType) {
if (!Objects.isNull(mapType) && !Objects.isNull(lat) && !Objects.isNull(lon)) {
try {
double latD = Double.parseDouble(lat);
double lonD = Double.parseDouble(lon);
double[] locationMap = translateResultLocationByMapType(latD, lonD, mapType);
return new String[]{CoordinateFormatUtil.format(locationMap[1]), CoordinateFormatUtil.format(locationMap[0])};
} catch (NumberFormatException var8) {
return new String[]{lon, lat};
}
} else {
return new String[]{lon, lat};
}
}
/**
* 根据地图类型转换为大地坐标系
*/
public static String[] getWGSLocationByMapType(String lon, String lat, Integer mapType) {
if (!Objects.isNull(mapType) && !Objects.isNull(lat) && !Objects.isNull(lon)) {
try {
double latD = Double.parseDouble(lat);
double lonD = Double.parseDouble(lon);
double[] locationMap = translateToWGSLocation(latD, lonD, mapType);
return new String[]{CoordinateFormatUtil.format(locationMap[1]), CoordinateFormatUtil.format(locationMap[0])};
} catch (NumberFormatException var8) {
return new String[]{lon, lat};
}
} else {
return new String[]{lon, lat};
}
}
public static double[] translateToWGSLocation(double lat, double lon, Integer mapType) {
if (mapType == null) {
return new double[]{lat, lon};
} else if (mapType == 1) {
return bd2wgs(lat, lon);
} else {
return mapType == 0 ? gcj2wgs(lat, lon) : new double[]{lat, lon};
}
}
public static double[] bd2wgs(double lat, double lon) {
double[] bd2gcj = bd2gcj(lat, lon);
return gcj2wgs(bd2gcj[0], bd2gcj[1]);
}
public static double[] gcj2wgs(double glat, double glon) {
double[] latlon = new double[2];
if (!ChinaMapUtil.isInsideChina(glat, glon)) {
latlon[0] = glat;
latlon[1] = glon;
return latlon;
} else {
double[] deltaD = delta(glat, glon);
latlon[0] = glat - deltaD[0];
latlon[1] = glon - deltaD[1];
return latlon;
}
}
public static double[] bd2gcj(double lat, double lon) {
if (!ChinaMapUtil.isInsideChina(lat, lon)) {
return new double[]{lat, lon};
} else {
double x = lon - 0.0065D;
double y = lat - 0.006D;
double z = Math.sqrt(x * x + y * y) - 2.0E-5D * Math.sin(y * 52.35987755982988D);
double theta = Math.atan2(y, x) - 3.0E-6D * Math.cos(x * 52.35987755982988D);
double gg_lon = z * Math.cos(theta);
double gg_lat = z * Math.sin(theta);
return new double[]{gg_lat, gg_lon};
}
}
public static double[] delta(double wgLat, double wgLon) {
double dLat = transformLat(wgLon - 105.0D, wgLat - 35.0D);
double dLon = transformLon(wgLon - 105.0D, wgLat - 35.0D);
double radLat = wgLat / 180.0D * pi;
double magic = Math.sin(radLat);
magic = 1.0D - ee * magic * magic;
double sqrtMagic = Math.sqrt(magic);
dLat = dLat * 180.0D / (a * (1.0D - ee) / (magic * sqrtMagic) * pi);
dLon = dLon * 180.0D / (a / sqrtMagic * Math.cos(radLat) * pi);
return new double[]{dLat, dLon};
}
public static double[] translateResultLocationByMapType(double lat, double lon, Integer mapType) {
if (mapType == null) {
return new double[]{lat, lon};
} else if (mapType == 1) {
return wgs2bd(lat, lon);
} else {
return mapType == 0 ? wgs2gcj4google(lat, lon) : new double[]{lat, lon};
}
}
public static double[] wgs2bd(double lat, double lon) {
double[] wgs2gcj = wgs2gcj(lat, lon);
return gcj2bd(wgs2gcj[0], wgs2gcj[1]);
}
public static double[] gcj2bd(double lat, double lon) {
if (!ChinaMapUtil.isInsideChina(lat, lon)) {
return new double[]{lat, lon};
} else {
double z = Math.sqrt(lon * lon + lat * lat) + 2.0E-5D * Math.sin(lat * 52.35987755982988D);
double theta = Math.atan2(lat, lon) + 3.0E-6D * Math.cos(lon * 52.35987755982988D);
double bd_lon = z * Math.cos(theta) + 0.0065D;
double bd_lat = z * Math.sin(theta) + 0.006D;
return new double[]{bd_lat, bd_lon};
}
}
public static double[] wgs2gcj(double lat, double lon) {
if (!ChinaMapUtil.isInsideChina(lat, lon)) {
return new double[]{lat, lon};
} else {
double[] deltaD = delta(lat, lon);
double mgLat = lat + deltaD[0];
double mgLon = lon + deltaD[1];
return new double[]{mgLat, mgLon};
}
}
public static double[] wgs2gcj4google(double lat, double lon) {
if (ChinaMapUtil.isInsideChina(lat, lon) && !ChinaMapUtil.isInsideTaiWan(lat, lon) && !ChinaMapUtil.isInsideXiangGang(lat, lon)) {
double[] deltaD = delta(lat, lon);
double mgLat = lat + deltaD[0];
double mgLon = lon + deltaD[1];
return new double[]{mgLat, mgLon};
} else {
return new double[]{lat, lon};
}
}
private static double transformLat(double lat, double lon) {
double ret = -100.0D + 2.0D * lat + 3.0D * lon + 0.2D * lon * lon + 0.1D * lat * lon + 0.2D * Math.sqrt(Math.abs(lat));
ret += (20.0D * Math.sin(6.0D * lat * pi) + 20.0D * Math.sin(2.0D * lat * pi)) * 2.0D / 3.0D;
ret += (20.0D * Math.sin(lon * pi) + 40.0D * Math.sin(lon / 3.0D * pi)) * 2.0D / 3.0D;
ret += (160.0D * Math.sin(lon / 12.0D * pi) + 320.0D * Math.sin(lon * pi / 30.0D)) * 2.0D / 3.0D;
return ret;
}
private static double transformLon(double lat, double lon) {
double ret = 300.0D + lat + 2.0D * lon + 0.1D * lat * lat + 0.1D * lat * lon + 0.1D * Math.sqrt(Math.abs(lat));
ret += (20.0D * Math.sin(6.0D * lat * pi) + 20.0D * Math.sin(2.0D * lat * pi)) * 2.0D / 3.0D;
ret += (20.0D * Math.sin(lat * pi) + 40.0D * Math.sin(lat / 3.0D * pi)) * 2.0D / 3.0D;
ret += (150.0D * Math.sin(lat / 12.0D * pi) + 300.0D * Math.sin(lat / 30.0D * pi)) * 2.0D / 3.0D;
return ret;
}
}