react中实现名称转换经纬度,经纬度转换名称
//地址查询经纬度 const geoCode = address => { geocoder.getLocation(address, (status, result) => { if (status === 'complete' && result.info === 'OK') { //status === 'complete' && result.geocodes.length var lnglat = result.geocodes[0].location; marker.setPosition(lnglat); // map.add(marker); // map.setFitView(marker); form.setFieldsValue({ lnglat: lnglat }); } else if (address === '' || address === null) { message.error('监测点地址为空'); } else { message.error('根据地址查询位置失败'); } }); };
//经纬度查询地址 const regeoCode = lnglat => { marker.setPosition(lnglat); geocoder.getAddress(lnglat, function (status, result) { if (status === 'complete' && result.regeocode) { var address = result.regeocode.formattedAddress; form.setFieldsValue({ address: address }); } else { message.error('根据经纬度查询地址失败'); } }); };
var geocoder = new window.AMap.Geocoder({
//city: "010", //城市设为北京,默认:“全国”
});
var marker = new window.AMap.Marker();