修复02坐标系偏移引起的bug
This commit is contained in:
parent
987a2f04c6
commit
c46b4a290d
@ -21,7 +21,7 @@ jar包maven依赖:
|
||||
` <dependency>
|
||||
<groupId>com.github.deng0515001</groupId>
|
||||
<artifactId>lnglat2Geo</artifactId>
|
||||
<version>1.0.4</version>
|
||||
<version>1.0.5</version>
|
||||
</dependency>`
|
||||
|
||||
有问题直接联系:QQ:451408963@qq.com
|
||||
|
2
pom.xml
2
pom.xml
@ -13,7 +13,7 @@
|
||||
</properties>
|
||||
<groupId>com.github.deng0515001</groupId>
|
||||
<artifactId>lnglat2Geo</artifactId>
|
||||
<version>1.0.4</version>
|
||||
<version>1.0.5</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>lnglat2Geo</name>
|
||||
<description>lnglat to Geo</description>
|
||||
|
Binary file not shown.
Binary file not shown.
@ -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
|
||||
}
|
||||
|
@ -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 => {
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
||||
|
@ -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 => {
|
||||
|
Loading…
Reference in New Issue
Block a user