diff --git a/README.md b/README.md
index f4a5d95..9a1c31b 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@ jar包maven依赖:
`
com.github.deng0515001
lnglat2Geo
- 1.0.4
+ 1.0.5
`
有问题直接联系:QQ:451408963@qq.com
diff --git a/pom.xml b/pom.xml
index d038e21..5c6774d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -13,7 +13,7 @@
com.github.deng0515001
lnglat2Geo
- 1.0.4
+ 1.0.5
jar
lnglat2Geo
lnglat to Geo
diff --git a/src/main/resources/china/boundary.data b/src/main/resources/china/boundary.data
index 8483204..355af63 100644
Binary files a/src/main/resources/china/boundary.data and b/src/main/resources/china/boundary.data differ
diff --git a/src/main/resources/china/boundaryCell.data b/src/main/resources/china/boundaryCell.data
index 4b3fd4a..bad6b01 100644
Binary files a/src/main/resources/china/boundaryCell.data and b/src/main/resources/china/boundaryCell.data differ
diff --git a/src/main/scala/com/dengxq.lnglat2Geo/GeoTransImpl.scala b/src/main/scala/com/dengxq.lnglat2Geo/GeoTransImpl.scala
index 9675198..99c6a5b 100644
--- a/src/main/scala/com/dengxq.lnglat2Geo/GeoTransImpl.scala
+++ b/src/main/scala/com/dengxq.lnglat2Geo/GeoTransImpl.scala
@@ -48,8 +48,8 @@ private[lnglat2Geo] object GeoTransImpl {
}
def determineAdmin(lon: Double, lat: Double, needStreet: Boolean = false, coordSys: CoordinateSystem = CoordinateSystem.GCJ02): Admin = {
- val gcj02LonLat = GeoUtils.toGCJ02(lon, lat, coordSys)
- val code = determineAdminCode(gcj02LonLat._1, gcj02LonLat._2)
+ val wgs84LonLat = GeoUtils.toWGS84(lon, lat, coordSys)
+ val code = determineAdminCode(wgs84LonLat._1, wgs84LonLat._2)
if (code != -1) {
val district = adminData.get(code).orNull
val city = if (district.level == DistrictLevel.District) adminData.get(district.parentId).orNull else district
@@ -60,7 +60,7 @@ private[lnglat2Geo] object GeoTransImpl {
if (needStreet) {
if (district.children.nonEmpty) {
val street = district.children.map(s => streetData.get(s))
- .minBy(s => GeoUtils.distance(s.get.center, Location(gcj02LonLat._1, gcj02LonLat._2))).get
+ .minBy(s => GeoUtils.distance(s.get.center, Location(wgs84LonLat._1, wgs84LonLat._2))).get
streetCode = street.id
streetName = street.name
}
diff --git a/src/main/scala/com/dengxq.lnglat2Geo/build/Upgrade.scala b/src/main/scala/com/dengxq.lnglat2Geo/build/Upgrade.scala
index 4b8d6bb..7d4a127 100644
--- a/src/main/scala/com/dengxq.lnglat2Geo/build/Upgrade.scala
+++ b/src/main/scala/com/dengxq.lnglat2Geo/build/Upgrade.scala
@@ -6,7 +6,7 @@ import java.text.Collator
import com.dengxq.lnglat2Geo.build.AdminDataProvider.{AMapData, DistrictLoader}
import com.google.common.geometry._
import com.dengxq.lnglat2Geo.entity._
-import com.dengxq.lnglat2Geo.utils.{AdminUtils, ObjectSerializer, S2Utils}
+import com.dengxq.lnglat2Geo.utils.{AdminUtils, GeoUtils, ObjectSerializer, S2Utils}
import com.dengxq.lnglat2Geo.utils.S2Utils.{childrenCellId, getLevel}
import com.dengxq.lnglat2Geo.GeoTransImpl.min_level
import AdminDataProvider._
@@ -55,9 +55,8 @@ object Upgrade {
val ss = loopStr.split(';')
.map(coordStr => {
val parts = coordStr.split(',')
- val lng = parts(0).toDouble
- val lat = parts(1).toDouble
- (lng, lat, S2LatLng.fromDegrees(lat, lng))
+ val wgs84 = GeoUtils.gcj02ToWgs84(parts(0).toDouble, parts(1).toDouble)
+ (wgs84._1, wgs84._2, S2LatLng.fromDegrees(wgs84._2, wgs84._1))
})
.sliding(2, 1)
.flatMap(slice => {
diff --git a/src/main/scala/com/dengxq.lnglat2Geo/utils/GeoUtils.scala b/src/main/scala/com/dengxq.lnglat2Geo/utils/GeoUtils.scala
index 09bc7ad..88cd489 100644
--- a/src/main/scala/com/dengxq.lnglat2Geo/utils/GeoUtils.scala
+++ b/src/main/scala/com/dengxq.lnglat2Geo/utils/GeoUtils.scala
@@ -151,6 +151,19 @@ object GeoUtils {
}
}
+ def toWGS84(lng: Double, lat:Double, coordType: CoordinateSystem.CoordinateSystem): (Double, Double) = {
+ coordType match {
+ case CoordinateSystem.GCJ02 =>
+ val d = GeoUtils.gcj02ToWgs84(lng, lat)
+ (d._1, d._2)
+ case CoordinateSystem.BD09 =>
+ val d02 = GeoUtils.bd09ToGCJ02(lng, lat)
+ val d = GeoUtils.gcj02ToWgs84(d02._1, d02._2)
+ (d._1, d._2)
+ case _ => (lng, lat)
+ }
+ }
+
@deprecated
def nearest[A](source: Array[A], loc: Location, locExpression: A => Location) :Option[A] = {
if(source == null || source.isEmpty) {
diff --git a/src/main/scala/com/dengxq.lnglat2Geo/utils/S2Utils.scala b/src/main/scala/com/dengxq.lnglat2Geo/utils/S2Utils.scala
index e6b5d5f..537229e 100644
--- a/src/main/scala/com/dengxq.lnglat2Geo/utils/S2Utils.scala
+++ b/src/main/scala/com/dengxq.lnglat2Geo/utils/S2Utils.scala
@@ -67,9 +67,8 @@ object S2Utils {
polylineString.split('|').foreach(loopStr => {
val points: Array[S2Point] = loopStr.split(';').map(coordStr => {
val parts = coordStr.split(',')
- val lng = parts(0).toDouble
- val lat = parts(1).toDouble
- S2LatLng.fromDegrees(lat, lng).toPoint
+ val wgs84 = GeoUtils.gcj02ToWgs84(parts(0).toDouble, parts(1).toDouble)
+ S2LatLng.fromDegrees(wgs84._2, wgs84._1).toPoint
})
val jPoints = points.toList.asJava
diff --git a/src/test/scala/com/dengxq/lnglat2Geo/AdminTest.scala b/src/test/scala/com/dengxq/lnglat2Geo/AdminTest.scala
index 71efe89..c9d5251 100644
--- a/src/test/scala/com/dengxq/lnglat2Geo/AdminTest.scala
+++ b/src/test/scala/com/dengxq/lnglat2Geo/AdminTest.scala
@@ -20,7 +20,7 @@ class AdminTest extends FlatSpec {
(116.4811706543,39.9255352817), // 北京市朝阳区 六里屯街道甜水园
(116.3362348080,40.0622912084), // 北京市昌平区 回龙观地区吉晟别墅社区
(116.3362830877,40.0594500522), // 北京市北京市昌平区 建材城西路65号
- (116.3325601816,40.0397393499), // 北京市海淀区 清河街道 小米六期
+ (116.3325601816,40.0397393499), // 北京市海淀区 清河街道
(117.0977783203,36.5085323575), // 山东省济南市历城区
(118.6358642578,35.8356283889), // 山东省临沂市沂水县
(119.7853088379,36.3029520437), // 山东省潍坊市高密市柏城镇
@@ -50,8 +50,8 @@ class AdminTest extends FlatSpec {
Admin.createDistrict( "山东省", "潍坊市", "高密市", 370700, 370700, 370785, Location(119.755597,36.382594)),
Admin.createDistrict("山东省", "青岛市", "胶州市", 370200, 370200, 370281, Location(120.033382,36.26468)),
Admin.createDistrict( "山东省", "青岛市", "城阳区", 370200, 370200, 370214, Location(120.396256,36.307559)),
- Admin.createDistrict("海外", "海外", "海外", 370200, 370200, -1, Location(120.396256,36.307559)),
- Admin.createDistrict("海外", "海外", "海外", 370200, 370200, -1, Location(120.396256,36.307559))
+ Admin.createDistrict("海外", "海外", "海外", -1, -1, -1, Location(120.396256,36.307559)),
+ Admin.createDistrict("海外", "海外", "海外", -1, -1, -1, Location(120.396256,36.307559))
)
"AdminArea.determineAdmin in scala " should "qps > 14w" in {
@@ -129,9 +129,9 @@ class AdminTest extends FlatSpec {
assert(admin.province == adminR.province)
assert(admin.city == adminR.city)
- assert(admin.cityID == adminR.cityID)
+ assert(admin.cityCode == adminR.cityCode)
assert(admin.district == adminR.district)
- assert(admin.districtID == adminR.districtID)
+ assert(admin.districtCode == adminR.districtCode)
})
// List().map(s => {