新增商圈地址经纬度
This commit is contained in:
+60
@@ -0,0 +1,60 @@
|
|||||||
|
package com.fangjia.script.temp.shenjian
|
||||||
|
|
||||||
|
import com.fangjia.script.util.MongoUtils
|
||||||
|
import com.fangjia.script.yinjihaun.amap.GaoDeApiUtils
|
||||||
|
import com.mongodb.BasicDBObject
|
||||||
|
import com.mongodb.DBCollection
|
||||||
|
import com.mongodb.DBObject
|
||||||
|
import net.sf.json.JSONObject
|
||||||
|
import org.bson.types.ObjectId
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取商圈地标
|
||||||
|
*
|
||||||
|
* @author shenjian
|
||||||
|
* @since 2021/4/13
|
||||||
|
*/
|
||||||
|
class BusinessDianpingAddr {
|
||||||
|
|
||||||
|
static DBCollection collection = MongoUtils.getCollectionByName("fangjia_crawl", "business", "192.168.0.235", 27018)
|
||||||
|
|
||||||
|
static void main(String[] args) {
|
||||||
|
def cities = ["苏州", "西安", "合肥"]
|
||||||
|
for (def city : cities) {
|
||||||
|
DBObject query = new BasicDBObject()
|
||||||
|
query.put("city", city)
|
||||||
|
collection.find(query).batchSize(300).each {obj ->
|
||||||
|
def id = obj._id
|
||||||
|
if (obj.lng == null || obj.lat == null) {
|
||||||
|
// 查询坐标位置,并更新
|
||||||
|
def location = this.parserByGaode(city, obj.address)
|
||||||
|
if (location != null) {
|
||||||
|
DBObject updateField = new BasicDBObject()
|
||||||
|
updateField.put("lng", location.lng)
|
||||||
|
updateField.put("lat", location.lat)
|
||||||
|
collection.update(new BasicDBObject('url', obj.url), new BasicDBObject('$set', updateField), false, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
collection.find()
|
||||||
|
}
|
||||||
|
|
||||||
|
static def parserByGaode(def city, def address) {
|
||||||
|
JSONObject json = GaoDeApiUtils.geo(city, address)
|
||||||
|
if (json && json.status == "1") {
|
||||||
|
def ret = json.geocodes
|
||||||
|
if (ret) {
|
||||||
|
def str = ret.get(0).location
|
||||||
|
def level = ret.get(0).level
|
||||||
|
if (str && ["门牌号", "单元号", "热点商圈", "兴趣点"].contains(level)) {
|
||||||
|
def arrs = str.split(",")
|
||||||
|
return ["lng": arrs[0], "lat": arrs[1]]
|
||||||
|
} else {
|
||||||
|
println address + " " + level
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user