When I get static map image via AJAX to check for the error, I get:
(当我通过AJAX获取静态地图图像以检查错误时,我得到:)
Refused to get unsafe header "x-staticmap-api-warning"
(拒绝获取不安全的标头“ x-staticmap-api-warning”)
(in chrome)
((镀铬))
I don't know much about headers, but it seems they had to be allowed on the server.
(我对标头了解不多,但是似乎必须在服务器上允许标头。)
It is right?(这是正确的?)
Or is there anything I can do?(还是我能做些什么?)
For completion my code:
(为了完成我的代码:)
getImageUrl(mapAddress) {
return "https://maps.googleapis.com/maps/api/staticmap?center=" + encodeURIComponent(mapAddress) + "&markers=color:red%7C" + encodeURIComponent(mapAddress) + "&zoom=17&size=" + this.state.boxWidth + "x" + this.state.boxHeight + "&maptype=roadmap&key=" + GOOGLE_KEY;
}
getImage(mapAddress) {
let url = this.getImageUrl(mapAddress);
let xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
// Ask for the result as an ArrayBuffer.
xhr.responseType = "arraybuffer";
xhr.onload = (e) => {
let warning;
try {
warning = xhr.getResponseHeader('x-staticmap-api-warning');
} catch (e) {}
if (warning && warning.indexOf('Error geocoding') === 0) {
this.setState({
imageFound: false,
loading: false
});
}
else {
let imageBlob = new Blob([new window.Uint8Array(xhr.response)]);
let imageUrl = URL.createObjectURL(imageBlob);
this.setState({
imageFound: true,
imageSrc: imageUrl,
loading: false
});
}
};
xhr.send();
}
ask by WuDo translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…