android高德地图逆地理,高德地图web服务api反坐标查询/逆地理编码

1、pom.xml

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

org.springframework.boot

spring-boot-starter-parent

2.1.3.RELEASE

com.api

gaodeapi

0.0.1-SNAPSHOT

gaodeapi

Demo project for Spring Boot

UTF-8

UTF-8

1.8

org.springframework.boot

spring-boot-starter

org.springframework.boot

spring-boot-starter-jdbc

org.mybatis.spring.boot

mybatis-spring-boot-starter

2.0.0

org.postgresql

postgresql

runtime

org.postgresql

postgresql

42.1.2

com.alibaba

druid

1.1.0

org.springframework.boot

spring-boot-starter-test

test

com.squareup.okhttp3

okhttp

3.10.0

com.squareup.okio

okio

1.13.0

com.alibaba

fastjson

1.2.47

junit

junit

org.springframework

spring-test

5.1.4.RELEASE

org.springframework.boot

spring-boot-test

org.springframework.boot

spring-boot-maven-plugin

2、代码

package com.tyxx.action;

import com.alibaba.fastjson.JSONArray;

import com.alibaba.fastjson.JSONObject;

import com.tyxx.GaodeapiApplication;

import com.tyxx.model.GdGPS;

import com.tyxx.service.GdGPSService;

import okhttp3.Call;

import okhttp3.OkHttpClient;

import okhttp3.Request;

import okhttp3.Response;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.boot.test.context.SpringBootTest;

import org.springframework.test.context.junit4.SpringRunner;

import java.io.IOException;

import java.util.List;

/**

* Created by cqy on 2019/3/18.

*/

@RunWith(SpringRunner.class)

@SpringBootTest(classes = {GaodeapiApplication.class})// 指定启动类

public class Test {

@Autowired

private GdGPSService gdGPSService;//数据查询和更新

@org.junit.Test

public void testSelect() {

List lt = gdGPSService.selAll();

for (int i = 0; i < lt.size(); i++) {

GdGPS gdGPS = lt.get(i);

System.out.println("id:" + gdGPS.getId());

String str = Test.gdapi(gdGPS.getJingdu(), gdGPS.getWeidu());

System.out.println("位置:" + str);

gdGPS.setAddress(str);

Integer row = gdGPSService.updatePri(gdGPS);

System.out.println(row + "-------------");

}

}

public static String gdapi(String jingdu, String weidu) {

String url = "https://restapi.amap.com/v3/geocode/regeo?output=json&location=" +

jingdu + "," + weidu + "&key=换成自己申请的key&radius=1000&extensions=all";

OkHttpClient okHttpClient = new OkHttpClient();

Request request = new Request.Builder().url(url).get().build();

Call call = okHttpClient.newCall(request);

String results = "";

try {

Response response = call.execute();

String result = response.body().string();

// System.out.println(result);

JSONObject json = JSONArray.parseObject(result);

// System.out.println(json);

// System.out.println(json.get("regeocode"));

JSONObject obj = JSONObject.parseObject(json.get("regeocode")

.toString());

System.out.println(obj.get("formatted_address"));

results = obj.get("formatted_address").toString();

} catch (IOException e) {

e.printStackTrace();

}

return results;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值