Geochart“请求的地图不存在"部署时 [英] Geochart "requested map does not exist" when deployed
问题描述
通过使用可视化 API,我能够获取秘鲁的本地地图(按省),并在本地开发我们的应用程序时使其正常工作.
By using the visualization API, i've been able to get a local map of Peru (by province) and got it working correctly while developing our application locally.
用于显示地图的代码如下:
The code used to display the map is the following:
function cargarMapa(departamento)
{
var data = google.visualization.arrayToDataTable([
['City'],
[departamento]
]);
var options = {
region: 'PE',
displayMode: 'regions',
resolution: 'provinces',
colorAxis: { colors: ['green'] },
width: 465,
height: 225
};
var geochart = new google.visualization.GeoChart(
document.getElementById('geochart_div'));
geochart.draw(data, options);
}
在我的电脑上工作时,它就像一个魅力:
And it works like a charm when working in my PC:
示例:
每当我运行应用程序(我使用 Visual Studio 2012 和 IIS 8)以及在我的笔记本电脑上部署它时(仅供参考,我在我的大学网络中这样做),它都可以工作.但是,当我在我大学的本地服务器 (IIS 7.5) 中部署它时,出现以下错误:
It works whenever i run the application (im using Visual Studio 2012 and IIS 8) and also when i deploy it on my laptop (FYI, im doing so while being in my University network). BUT, when i deploy this in my University's local server (IIS 7.5), i get the following error:
仅供参考,我使用了可视化 API 中的其他图表,它们完美加载
FYI, i use other charts from the visualization API and they load perfectly
代码完全一样,请问是什么问题?
The code is exactly the same so, what could the issue be?
提前致谢!
推荐答案
您遇到的问题是这一行:
The problem you are having is with this line:
google.setOnLoadCallback(cargarMapa(departamento));
当您在函数名称后包含 (
null
在这种情况下cargarMapa
).google.setOnLoadCallback(null);
不做任何事情,在 API 加载完成之前调用 cargarMapa
会导致问题,其中之一是您的地图尚未加载.
When you include (<arguments>)
after a function name, you are calling the function, which executes immediately and returns some value (null
in the case of cargarMapa
). google.setOnLoadCallback(null);
doesn't do anything, and calling cargarMapa
before the API is done loading causes issues, one of which is that your maps haven't loaded.
为了解决这个问题,创建一个新的函数来调用 cargarMapa(departamento);
:
To fix this, create a new function that calls cargarMapa(departamento);
:
function init () {
cargarMapa(departamento);
}
并将其设置为回调:
google.setOnLoadCallback(init);
注意 init
之后没有括号 (()
) - 这将函数 init
作为参数传递给回调处理程序,只是就像一个变量(从技术上讲,在 JavaScript 中,函数和变量是一回事——它们都是对象).
Notice there are no parenthesis (()
) after init
- this passes the function init
to the callback handler as an argument, just like a variable (technically, in javascript, functions and variables are the same thing - they're all objects).
这篇关于Geochart“请求的地图不存在"部署时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!