wgs84坐标转百度坐标和高德坐标

wgs84转百度坐标代码:

//longi 经度        lati   纬度
public Map<String,String> convertLatitudeAndLongitude(String longi,String lati){
        String urlPrefix = "http://api.map.baidu.com/geoconv/v1/?coords=";
        String urlSuffixfix = "&from=1&to=5&ak=go8tg3oNKkk39pop9GTEMX6RaCGWdeN2";
        Map<String,String> map = new HashMap<>();
        try{
            String url = urlPrefix+longi+","+lati+urlSuffixfix;
            Map<String, String> headMap = new HashMap<>();
            String result = HttpRequestUtils.httpGet(url);
            if(null != result){
                JSONObject jsonObject = JSONObject.parseObject(result);
                Integer status = jsonObject.getInteger("status");
                if(status == 0){
                    JSONArray jsonArray = jsonObject.getJSONArray("result");
                    JSONObject data = jsonArray.getJSONObject(0);
                    BigDecimal x = data.getBigDecimal("x");
                    BigDecimal y = data.getBigDecimal("y");
                    map.put("X",x.setScale(6,BigDecimal.ROUND_CEILING).toString());
                    map.put("Y",y.setScale(6,BigDecimal.ROUND_CEILING).toString());
                }

            }
            return map;
        }catch (Exception e){
            e.printStackTrace();
            return map;
        }

    }

wgs84转高德坐标代码:

public Map<String,String> convertLatitudeAndLongitudeToGaoDe(String longi,String lati){
		String urlPrefix = "https://restapi.amap.com/v3/assistant/coordinate/convert?locations=";
		String urlSuffixfix = "&coordsys=gps&output=json&key=deaa723314d16df3bd1c9dcbcb3f7b56";
		String returnResult = "高德坐标转换失败";
        Map<String,String> map = new HashMap<>();
		try{
				String url = urlPrefix+longi+","+lati+urlSuffixfix;
				Map<String, String> headMap = new HashMap<>();
				String result = HttpClientPoolUtil.get(url, headMap);
				if(null != result){
					JSONObject jsonObject = JSONObject.parseObject(result);
					Integer status = jsonObject.getInteger("status");
					if(status == 1){
						String locations = jsonObject.getString("locations");
						String[] split = locations.split(",");
						BigDecimal x = new BigDecimal(split[0]);
						BigDecimal y = new BigDecimal(split[1]);
						map.put("lati",y.setScale(6,BigDecimal.ROUND_CEILING).toString());
						map.put("longi",x.setScale(6,BigDecimal.ROUND_CEILING).toString());
					}

				}
			returnResult = "高德坐标转换成功";
			return map;
		}catch (Exception e){
			e.printStackTrace();
			return returnResult;
		}

	}

上面百度坐标转换用到的参数ak和高德坐标转换用到的参数key需要到对应地图开放平台去注册获取

百度开放平台地址:百度地图开放平台 | 百度地图API SDK | 地图开发

 点击控制台进入应用管理页面,查看ak:

 高德地图开放平台地址:高德开放平台 | 高德地图API

点击控制台进入应用管理页面,查看key: 

 

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值