服务端代理配置nginx(放伪静态配置或者站点配置文件都行)
# Web服务API 代理
location /_AMapService/ {
set $args "$args&jscode=你的安全密钥";
proxy_pass https://restapi.amap.com/;
}
前端
<script type="text/javascript">
window._AMapSecurityConfig = {
serviceHost: "_AMapService"
};
</script>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=2.0&key=你的key"></script>
<script type="text/javascript">
AMap.plugin('AMap.Weather', function() {
var weather = new AMap.Weather();
weather.getForecast('上海市', function(err, data) {
console.log(data);
if(data.info=='OK'){
}else{
}
});
});
</script>