优化经纬度获取

This commit is contained in:
沈健
2021-09-09 15:44:24 +08:00
parent 81091958d5
commit 35ab32f65e
3 changed files with 19 additions and 12 deletions
@@ -12,7 +12,7 @@ import com.fangjia.script.util.DateUtils
class DingTalkUtils { class DingTalkUtils {
static main(String[] args) { static main(String[] args) {
Date now = DateUtils.parseFromTightByPattern("2021-07-01", "yyyy-MM-dd") ; Date now = DateUtils.parseFromTightByPattern("2021-08-01", "yyyy-MM-dd") ;
String startTime = DateUtils.addMonth(now, -1) + " 00:00:00" String startTime = DateUtils.addMonth(now, -1) + " 00:00:00"
String monthStartTime = DateUtils.formatDateByPattern(now, "yyyy-MM-dd HH:mm:ss") String monthStartTime = DateUtils.formatDateByPattern(now, "yyyy-MM-dd HH:mm:ss")
@@ -1,5 +1,6 @@
package com.fangjia.script.temp.shenjian.poi package com.fangjia.script.temp.shenjian.poi
import com.fangjia.script.statistics.poi.AmapPoi
import com.fangjia.script.temp.shenjian.util.GaoDeUtils import com.fangjia.script.temp.shenjian.util.GaoDeUtils
import com.fangjia.script.util.MongoUtils import com.fangjia.script.util.MongoUtils
import com.mongodb.BasicDBObject import com.mongodb.BasicDBObject
@@ -18,7 +19,7 @@ import java.util.concurrent.Executors
class CommitteeLatLng { class CommitteeLatLng {
static DBCollection villagesConn = MongoUtils.getCollectionByName("fangjia", "villages", "192.168.0.43", 28017) static DBCollection villagesConn = MongoUtils.getCollectionByName("fangjia", "villages", "192.168.0.43", 28017)
static ExecutorService executorService = Executors.newFixedThreadPool(30) static ExecutorService executorService = Executors.newFixedThreadPool(1)
static void main(String[] args) { static void main(String[] args) {
dealPoi(new BasicDBObject("status_location", new BasicDBObject('$ne', 0))) dealPoi(new BasicDBObject("status_location", new BasicDBObject('$ne', 0)))
@@ -37,12 +38,16 @@ class CommitteeLatLng {
city = obj.province_name city = obj.province_name
} }
def address = obj.province_name + city + obj.area_name + obj.street_name + obj.name; def address = obj.province_name + city + obj.area_name + obj.street_name + obj.name;
def location = GaoDeUtils.parserByGaode(city, address); // 不准确
if (location && location.lng) { // def location = GaoDeUtils.parserByGaode(city, address);
def lng = Double.valueOf(location.lng) List<AmapPoi> amapPoi = GaoDeUtils.searchPoi(city, address, obj.area_name, "130106|130105|130104")
def lat = Double.valueOf(location.lat) if (amapPoi && amapPoi.size() > 0) {
def poi = amapPoi[0]
String[] locations = poi.location.split(",")
def lng = Double.valueOf(locations[0])
def lat = Double.valueOf(locations[1])
villagesConn.update(new BasicDBObject("_id", obj._id), new BasicDBObject('$set', new BasicDBObject("status_location", 0) villagesConn.update(new BasicDBObject("_id", obj._id), new BasicDBObject('$set', new BasicDBObject("status_location", 0)
.append("location", new BasicDBObject("lat", lat).append("lon", lng)).append("flag_location", "已获取经纬度"))) .append("location", new BasicDBObject("lat", lat).append("lon", lng)).append("flag_location", "关键字搜索获取经纬度")))
} else { } else {
villagesConn.update(new BasicDBObject("_id", obj._id), new BasicDBObject('$set', new BasicDBObject("status_location", 2).append("flag_location", "经纬度为空"))) villagesConn.update(new BasicDBObject("_id", obj._id), new BasicDBObject('$set', new BasicDBObject("status_location", 2).append("flag_location", "经纬度为空")))
} }
@@ -128,9 +128,9 @@ class GaoDeUtils {
while (result.size() < count) { while (result.size() < count) {
params.page = "${page}".toString() params.page = "${page}".toString()
page++ page++
JSONObject json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v3/place/around", params); JSONObject json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v5/place/around", params);
if (json == null) { if (json == null) {
json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v3/place/around", params); json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v5/place/around", params);
} }
if (json && json.info && json.info == "OK") { if (json && json.info && json.info == "OK") {
count = json.getString("count").toInteger() count = json.getString("count").toInteger()
@@ -169,11 +169,13 @@ class GaoDeUtils {
/** /**
* 查找关键字经纬度 * 查找关键字经纬度
*/ */
static List searchPoi(String city, String keywords){ static List searchPoi(String city, String keywords, String region, String typecodes){
def params = [:] def params = [:]
params.key = GAO_DE_AK[keyUsed.intValue()] params.key = GAO_DE_AK[keyUsed.intValue()]
params.keywords = keywords params.keywords = keywords
params.city = city params.city = city
params.region = region
params.types = typecodes
params.put("extensions", "all") params.put("extensions", "all")
params.put("citylimit","true") params.put("citylimit","true")
params.put("offset","20") params.put("offset","20")
@@ -184,9 +186,9 @@ class GaoDeUtils {
while (result.size() < count) { while (result.size() < count) {
params.page = "${page}".toString() params.page = "${page}".toString()
page++ page++
JSONObject json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v3/place/text", params); JSONObject json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v5/place/text", params);
if (json == null) { if (json == null) {
json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v3/place/text", params); json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v5/place/text", params);
} }
if (json && json.info && json.info == "OK") { if (json && json.info && json.info == "OK") {
count = json.getString("count").toInteger() count = json.getString("count").toInteger()