您当前的位置: 首页 > 

漏刻有时

暂无认证

  • 0浏览

    0关注

    717博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

高德地图进阶开发实战案例(1):webAPI坐标转换和jsAPI批量转换

漏刻有时 发布时间:2021-04-26 20:22:27 ,浏览量:0

坐标转换是一类简单的HTTP接口,能够将用户输入的非高德坐标(GPS坐标、mapbar坐标、baidu坐标)转换成高德坐标。

webAPI坐标转换 JS函数封装
    /*
     * coordsys,原坐标系,可选值:gps;mapbar;baidu;autonavi(不进行转换)
     * */
    function convertPoints(points, coordsys, keys) {
        var url = "https://restapi.amap.com/v3/assistant/coordinate/convert?locations=" + points + "&coordsys=" + coordsys + "&output=json&key=" + keys;
        $.getJSON(url, function (res) {
            //console.log(res);
            $("#coords").html(res.locations);
        })
    }
    var points = "121.554586,29.813444";
    var coordsys = "baidu";
    var keys = "4d9a765939a**";

    //函数调用;
    convertPoints(points, coordsys, keys);
成功返回的数据格式

在这里插入图片描述

jsAPI批量转换
    var map = new AMap.Map('container', {
        center: [121.548181, 29.806906],
        zoom: 15
    });
    
    // 创建包含4个节点的折线及文字标注
    var path = [
        new AMap.LngLat(121.552371,29.813682),
        new AMap.LngLat(121.555713,29.812867)
    ];

    // 坐标转换
    /*
    * type用于说明是哪个服务商的坐标,可选值有:
     gps:GPS原始坐标;
     baidu:百度经纬度;
     mapbar:图吧经纬度;*/
    AMap.convertFrom(path, 'baidu', function (status, result) {
        console.log(result);
        if (result.info === 'ok') {
            var path2 = result.locations;
            polyline2 = new AMap.Polyline({
                path: path2,
                borderWeight: 2, // 线条宽度,默认为 1
                strokeColor: 'blue', // 线条颜色
                lineJoin: 'round' // 折线拐点连接处样式
            });
            map.add(polyline2);
        }
    });
成功返回的数据格式

在这里插入图片描述

lockdatav Done!

关注
打赏
1661217259
查看更多评论
立即登录/注册

微信扫码登录

0.0403s