【地图API】收货地址详解2

时间:2022-06-26 04:23:22

function geocoder() { var myGeo = new AMap.Geocoder(); //地理编码,返回地理编码结果 myGeo.getLocation($addressBox.value, function(status, result) { if (status === ‘complete‘ && result.info === ‘OK‘) { //地址解析成功 geocoder_CallBack(result); } else{ //地址解析失败 $pointBox.innerHTML = "查无此地址"; } }); } //地理编码返回结果展示 function geocoder_CallBack(data) { var resultStr = ""; var geocode = data.geocodes; var myLng = geocode[0].location.getLng(); var myLat = geocode[0].location.getLat(); resultStr += "当前坐标</b>:" + myLng + ", " + myLat; $pointBox.innerHTML = resultStr; map.setCenter(new AMap.LngLat(myLng,myLat)); }