日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java api从高德地图获取某个位置的经纬度

發布時間:2024/3/26 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java api从高德地图获取某个位置的经纬度 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、代碼展示

import com.fasterxml.jackson.databind.JsonNode; import com.ning.http.client.AsyncHttpClient; import com.ning.http.client.AsyncHttpClientConfig; import com.ning.http.client.ListenableFuture; import com.ning.http.client.Response; import com.sun.deploy.net.HttpUtils; import org.mortbay.util.UrlEncoded;/*** 通過java api從高德地圖獲取經緯度* address 位置* output 返回結果格式* key 高德key值,需申請*/public class Distance {public static void main(String[] args) {//1、通過java api從高德地圖獲取經緯度String url = "http://restapi.amap.com/v3/geocode/geo?address=上海市東方明珠&output=JSON&key=xxxxxxxxx";AsyncHttpClientConfig.Builder builder = new AsyncHttpClientConfig.Builder();builder.setCompressionEnabled(true).setAllowPoolingConnection(true);builder.setRequestTimeoutInMs((int) TimeUnit.MINUTES.toMillis(1));builder.setIdleConnectionTimeoutInMs((int) TimeUnit.MINUTES.toMillis(1));AsyncHttpClient client = new AsyncHttpClient(builder.build());try {ListenableFuture<Response> future = client.prepareGet(url).execute();String result = future.get().getResponseBody();System.out.println(result);JsonNode jsonNode = new com.fasterxml.jackson.databind.ObjectMapper().readTree(future.get().getResponseBody());if(jsonNode.findValue("status").textValue().equals("1")) {JsonNode listSource = jsonNode.findValue("location");System.out.println(listSource);for(String location : listSource.textValue().split(",")){//得到這個位置的經緯度System.out.println(location);//System.out.println(Double.valueOf(location));}}} catch (Exception e) {e.printStackTrace();} finally {if(client != null){client.close();}}} }

2、詳細請看高德官網api介紹:
http://lbs.amap.com/api/webservice/reference/georegeo/

總結

以上是生活随笔為你收集整理的java api从高德地图获取某个位置的经纬度的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。