优化key获取
This commit is contained in:
+23
-9
@@ -54,8 +54,10 @@ class GaoDeUtils {
|
||||
* 获取高德KEY
|
||||
* @return
|
||||
*/
|
||||
static String getGaodeKey() {
|
||||
JSONObject json = HttpRequestUtil.getJsonContent("http://192.168.0.100:38080/FangJiaDataService/getAmapKey", new HashMap<String, String>())
|
||||
static String getGaodeKey(String type) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("type", type)
|
||||
JSONObject json = HttpRequestUtil.getJsonContent("http://192.168.0.100:38080/FangJiaDataService/getAmapKey", params)
|
||||
if (json.status == 0 && json.result != null) {
|
||||
return json.result
|
||||
}
|
||||
@@ -74,7 +76,7 @@ class GaoDeUtils {
|
||||
*/
|
||||
static List searchNearByPoi(String city, String types, Double lng, Double lat, Integer radius, String keywords){
|
||||
def params = [:]
|
||||
params.key = this.getGaodeKey()
|
||||
|
||||
|
||||
if (types) {
|
||||
params.types = types
|
||||
@@ -91,8 +93,10 @@ class GaoDeUtils {
|
||||
while (result.size() < count) {
|
||||
params.page = "${page}".toString()
|
||||
page++
|
||||
params.key = this.getGaodeKey("v3/place/around")
|
||||
JSONObject json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v3/place/around", params);
|
||||
if (json == null) {
|
||||
params.key = this.getGaodeKey("v3/place/around")
|
||||
json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v3/place/around", params);
|
||||
}
|
||||
if (json && json.info && json.info == "OK") {
|
||||
@@ -126,7 +130,6 @@ class GaoDeUtils {
|
||||
*/
|
||||
static List searchNearDtoByPoi(String city, String types, Double lng, Double lat, Integer radius, String keywords){
|
||||
def params = [:]
|
||||
params.key = this.getGaodeKey()
|
||||
|
||||
if (types) {
|
||||
params.types = types
|
||||
@@ -143,8 +146,10 @@ class GaoDeUtils {
|
||||
while (result.size() < count) {
|
||||
params.page = "${page}".toString()
|
||||
page++
|
||||
params.key = this.getGaodeKey("v5/place/around")
|
||||
JSONObject json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v5/place/around", params);
|
||||
if (json == null) {
|
||||
params.key = this.getGaodeKey("v5/place/around")
|
||||
json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v5/place/around", params);
|
||||
}
|
||||
if (json && json.info && json.info == "OK") {
|
||||
@@ -211,11 +216,12 @@ class GaoDeUtils {
|
||||
*/
|
||||
static List<AmapPoi> getAmapById(id){
|
||||
def params = [:]
|
||||
params.key = this.getGaodeKey()
|
||||
params.id = id
|
||||
params.output = 'json'
|
||||
params.key = this.getGaodeKey("v3/place/detail")
|
||||
JSONObject json = HttpRequestUtil.getJsonContent("https://restapi.amap.com/v3/place/detail", params);
|
||||
if (json == null) {
|
||||
params.key = this.getGaodeKey("v3/place/detail")
|
||||
json = HttpRequestUtil.getJsonContent("https://restapi.amap.com/v3/place/detail", params);
|
||||
}
|
||||
if (json && json.info && json.info == "OK") {
|
||||
@@ -242,11 +248,12 @@ class GaoDeUtils {
|
||||
*/
|
||||
static List<AmapPoiDetail> getAmapDetailById(id){
|
||||
def params = [:]
|
||||
params.key = this.getGaodeKey()
|
||||
params.id = id
|
||||
params.output = 'json'
|
||||
params.key = this.getGaodeKey("v3/place/detail")
|
||||
JSONObject json = HttpRequestUtil.getJsonContent("https://restapi.amap.com/v3/place/detail", params);
|
||||
if (json == null) {
|
||||
params.key = this.getGaodeKey("v3/place/detail")
|
||||
json = HttpRequestUtil.getJsonContent("https://restapi.amap.com/v3/place/detail", params);
|
||||
}
|
||||
if (json && json.info && json.info == "OK") {
|
||||
@@ -273,7 +280,6 @@ class GaoDeUtils {
|
||||
*/
|
||||
static List searchPoi(String city, String keywords, String region, String typecodes){
|
||||
def params = [:]
|
||||
params.key = this.getGaodeKey()
|
||||
params.keywords = keywords
|
||||
params.city = city
|
||||
params.region = region
|
||||
@@ -290,8 +296,10 @@ class GaoDeUtils {
|
||||
while (result.size() < count) {
|
||||
params.page = "${page}".toString()
|
||||
page++
|
||||
params.key = this.getGaodeKey("v5/place/text")
|
||||
JSONObject json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v5/place/text", params);
|
||||
if (json == null) {
|
||||
params.key = this.getGaodeKey("v5/place/text")
|
||||
json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v5/place/text", params);
|
||||
}
|
||||
if (json && json.info && json.info == "OK") {
|
||||
@@ -333,12 +341,13 @@ class GaoDeUtils {
|
||||
*/
|
||||
static def getGaoDeAddress(location) {
|
||||
Map<String, String> params = new HashMap<String, String>()
|
||||
params.put("key", this.getGaodeKey())
|
||||
params.put("location", location)
|
||||
String content
|
||||
try {
|
||||
params.put("key", this.getGaodeKey("v3/geocode/regeo"))
|
||||
content = new HttpRequest().get("http://restapi.amap.com/v3/geocode/regeo", params, "utf-8")
|
||||
} catch (Exception e) {
|
||||
params.put("key", this.getGaodeKey("v3/geocode/regeo"))
|
||||
content = new HttpRequest().get("http://restapi.amap.com/v3/geocode/regeo", params, "utf-8")
|
||||
}
|
||||
net.sf.json.JSONObject json = net.sf.json.JSONObject.fromObject(content)
|
||||
@@ -365,13 +374,14 @@ class GaoDeUtils {
|
||||
*/
|
||||
static def parserByGaode(def city, def address) {
|
||||
Map<String, String> params = new HashMap<String, String>()
|
||||
params.put("key", this.getGaodeKey())
|
||||
params.put("city", city)
|
||||
params.put("address", address)
|
||||
String content
|
||||
try {
|
||||
params.put("key", this.getGaodeKey("v3/geocode/geo"))
|
||||
content = new HttpRequest().get("https://restapi.amap.com/v3/geocode/geo", params, "utf-8")
|
||||
} catch (Exception e) {
|
||||
params.put("key", this.getGaodeKey("v3/geocode/geo"))
|
||||
content = new HttpRequest().get("https://restapi.amap.com/v3/geocode/geo", params, "utf-8")
|
||||
}
|
||||
net.sf.json.JSONObject json = net.sf.json.JSONObject.fromObject(content)
|
||||
@@ -393,4 +403,8 @@ class GaoDeUtils {
|
||||
System.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
static void main(String[] args) {
|
||||
println(this.getGaodeKey("v3/geocode/geo"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user