测试:使用高德地图把经纬度转为商圈

第一次使用高德地图,经纬对转换为商圈,测试如下
def parseGaodeJson(jsonStr: String) = {
val areaList: List[JsonAST.JValue] = JsonMethods.parse(jsonStr).\(“businessAreas”).children
var areaSet: mutable.Set[String] = new mutable.HashSetString

for (area <- areaList) {
  val areaName: String = area.\("name").values.toString
  areaSet += areaName
}

areaSet.mkString(":")

def loadGaode2Area(longitude: Double, latitude: Double): String = {
//请求高德
val jsonStr: String = getLocationInfo(longitude, latitude)
//解析json
val result: String = parseGaodeJson(jsonStr)
println(result)
result
}
//请求高德,返回JSON字符串
def getLocationInfo(longitude: Double, latitude: Double): String = {
//1.OkhttpClient
val okHttpClient = new OkHttpClient()
//2.Request
val config: Config = ConfigFactory.load(“common.conf”)
val url = config.getString(“amap.baseUrl”) +
“?location=” + longitude + “,” + latitude +
“&key=” + config.getString(“amap.key”)
val request: Request = new Request.Builder().url(url).get.build
//3.execute Response
val response: Response = okHttpClient.newCall(request).execute()
//4.body
if (response.isSuccessful) {
response.body().string()
} else {
“”
}
}
//main方法测试
def main(args: Array[String]): Unit = {
loadGaode2Area(115.480881, 34.989410)
}
}

你可能感兴趣的:(商圈)