使用高德地图poi获取数据,并在地图打点

401 阅读1分钟
  var style = [
    {
      url: "https://webapi.amap.com/images/mass/mass0.png",
      anchor: new AMap.Pixel(6, 6),
      size: new AMap.Size(11, 11),
      zIndex: 3
    },
    {
      url: "https://webapi.amap.com/images/mass/mass1.png",
      anchor: new AMap.Pixel(4, 4),
      size: new AMap.Size(7, 7),
      zIndex: 2
    },
    {
      url: "https://webapi.amap.com/images/mass/mass2.png",
      anchor: new AMap.Pixel(3, 3),
      size: new AMap.Size(5, 5),
      zIndex: 1
    }
  ];      var style = [
    {
      url: "https://webapi.amap.com/images/mass/mass0.png",
      anchor: new AMap.Pixel(6, 6),
      size: new AMap.Size(11, 11),
      zIndex: 3
    },
    {
      url: "https://webapi.amap.com/images/mass/mass1.png",
      anchor: new AMap.Pixel(4, 4),
      size: new AMap.Size(7, 7),
      zIndex: 2
    },
    {
      url: "https://webapi.amap.com/images/mass/mass2.png",
      anchor: new AMap.Pixel(3, 3),
      size: new AMap.Size(5, 5),
      zIndex: 1
    }
  ];
    
    
    //点标记
    let params = {
      key: "5c8b4918731d7d20bd6a065659c234f5",
      keywords: "重庆市沙坪坝区井熙路井口工业园东南侧约1"
    };
    axios
      .get("https://restapi.amap.com/v5/place/text", {
        params: params
      })
      .then(res => {
        //请求成功执行
        points.value = res.data.pois;
        console.log(res);
        transform(points.value);
        console.log(11111111111111);

        var mass = new AMap.MassMarks(points.value, {
          opacity: 0.8,
          zIndex: 111,
          cursor: "pointer",
          style: style
        });

        var marker = new AMap.Marker({ content: " ", map: map.value });

        mass.on("mouseover", function(e) {
          marker.setPosition(e.data.lnglat);
          marker.setLabel({ content: e.data.name });
        });

        mass.setMap(map.value);
      })
      .catch(error => {
        //请求失败执行
        console.log(error);
        console.log(222222222);
      });
      
      
      
      
      转换方法
      //转换poi中的经纬度
        const transform = points => {
          points.forEach((item, index) => {
            let locationString = item.location;
            let arr = locationString.split(",");
            item["lnglat"] = arr;
          });

          console.log(points);
        };