腾讯地图的输入提示

腾讯地图的输入提示

$.ajax({
     
    type: 'get',
    async : false,
    dataType:"jsonp",
    url: "https://apis.map.qq.com/ws/place/v1/suggestion?output=jsonp",
    data : {
     
        region:"全国",
        keyword:text,
        key:"HJ5BZ-AJA6F-5Z6JV-JBTV6-SOXHH-WYBWS",
    },
   success: function(result){
     
                    var list = result.data;
                    var strHtml = '';
                    if((result.status == 0) && (list.length != 0)){
     
                        for (var i=0;i<list.length;i++) {
     
                            var dispose = list[i].title;
                            // 处理title 带有市和省
                            if(list[i].title.includes(list[i].province)){
     
                                dispose = list[i].title.split(list[i].province)[1]
                            }
                            if(dispose.includes(list[i].city)){
     
                                dispose = dispose.split(list[i].city)[1];
                            }
                            if(dispose.includes(list[i].district)){
     
                                dispose = dispose.split(list[i].district)[1];
                            }


                            strHtml=strHtml+ `
${ list[i].province}${ list[i].city}${ list[i].district}${ dispose}">
`
} } //为避免输入省 出现重复 if(strHtml == ''){ element.addClass('hidden'); }else{ element.removeClass('hidden').append(strHtml); } }, error:function(error){ console.log("error"); } });

你可能感兴趣的:(PC攻略,javascript)