javascript 关于本地主机问题的 Google Maps API
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8233156/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Google Maps API on Localhost Issue
提问by Patricia
I'm brand new to working with the google maps api, and i've been stuck on this for a while now. i searched around and couldn't find much on why this is happening.
我是使用 google maps api 的新手,我已经坚持了一段时间了。我四处搜索,但找不到太多关于为什么会发生这种情况的信息。
the problem seems to be with this request: http://maps.googleapis.com/maps/api/js/AuthenticationService.Authenticate?1shttp%3A%2F%2Flocalhost%2FjQUeryMobile%2FHome%2FContact&callback=xdc._g5hc9f&token=122839
问题似乎与此请求有关:http: //maps.googleapis.com/maps/api/js/AuthenticationService.Authenticate ?1shttp%3A%2F%2Flocalhost%2FjQUeryMobile%2FHome%2FContact&callback= xdc._g5hc9f&token=122839
the bold part is obviously a problem. this parameter doesn't seem to be being built properly.
粗体部分显然是一个问题。此参数似乎没有正确构建。
i don't have any control over this though, this is all done by the maps stuff.
我对此没有任何控制权,这一切都是由地图的东西完成的。
here's my line for including the maps script:
这是我包含地图脚本的行:
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3&sensor=false&callback=initializeGeoCoder"></script>
function initializeGeoCoder(){
alert('initialize');
geoCoder = new GClientGeocoder();
}
interestingly enough, that alert does fire, but then nothing happens.
有趣的是,该警报确实触发了,但随后什么也没有发生。
maybe important details about my setup:
也许关于我的设置的重要细节:
i'm running iis locally on windows 7. the project is a .net 3.5 mvc 2.0 project. with jquery and jquery mobile.
我在 Windows 7 上本地运行 iis。该项目是一个 .net 3.5 mvc 2.0 项目。使用 jquery 和 jquery mobile。
i've tried it in FF, chrome, safari and IE.
我已经在 FF、chrome、safari 和 IE 中尝试过。
is it really a case of the api not being able to handle running on localhost? how does anyone do any testing?
这真的是 api 无法处理在本地主机上运行的情况吗?怎么有人做任何测试?
EDIT: looking into this even further, i looked at the requests for some of the samples. http://code.google.com/apis/maps/documentation/javascript/examples/map-simple.html
编辑:进一步研究这一点,我查看了对一些样本的请求。 http://code.google.com/apis/maps/documentation/javascript/examples/map-simple.html
it has a request pretty well the same: http://maps.googleapis.com/maps/api/js/AuthenticationService.Authenticate?1shttp%3A%2F%2Fcode.google.com%2Fapis%2Fmaps%2Fdocumentation%2Fjavascript%2Fexamples%2Fmap-simple.html&callback=xdc._56yxp&token=74698
它有一个非常相同的请求:http: //maps.googleapis.com/maps/api/js/AuthenticationService.Authenticate?1shttp%3A%2F%2Fcode.google.com%2Fapis%2Fmaps%2Fdocumentation%2Fjavascript%2Fexamples %2Fmap-simple.html&callback= xdc._56yxp&token=74698
which returns:
返回:
_xdc_._56yxp && _xdc_._56yxp( [1,null,0] )
mine returns:
我的回报:
_xdc_._10kda1 && _xdc_._10kda1( [1,null,0] )
i originally thought this was gibberish b/c of the request url being bad. but it seems that might not be the case.
我最初认为这是请求 url 错误的胡言乱语。但似乎情况并非如此。
some more information:
更多信息:
when running in IE, with script debugging running: this line fails:
在 IE 中运行时,运行脚本调试:此行失败:
EDIT: More Information:
编辑:更多信息:
when running it in IE, with script debugging. i get an error on this line:
在 IE 中运行时,带有脚本调试。我在这一行收到一个错误:
geoCoder = new GClientGeocoder();
the error is:
错误是:
'GClientGeocoder' is undefined
'GClientGeocoder' 未定义
so: something from the maps api isn't getting loaded all the way it seems.
所以:地图 api 中的某些内容并没有像看起来那样一直加载。
采纳答案by Derek
You're going to need to post more code than that. Post the div which contains your map.
您将需要发布更多代码。发布包含您的地图的 div。
The GClientGeocoder function doesn't insert a map into your page. In fact, it does something completely different (input an address and it will return lat/long).
GClientGeocoder 函数不会将地图插入您的页面。事实上,它做了一些完全不同的事情(输入一个地址,它会返回纬度/经度)。
Use this tutorial to start with a simple Google map.
使用本教程从一个简单的 Google 地图开始。
http://code.google.com/apis/maps/documentation/javascript/tutorial.html
http://code.google.com/apis/maps/documentation/javascript/tutorial.html
EDIT: If you are trying to use geocoding, then V3 of the Google Maps API names the function geocode() rather than GClientGeocoder(). Check out the source code of this demo: http://code.google.com/apis/maps/documentation/javascript/examples/geocoding-simple.html
编辑:如果您尝试使用地理编码,则 Google Maps API 的 V3 将函数命名为 geocode() 而不是 GClientGeocoder()。查看此演示的源代码:http: //code.google.com/apis/maps/documentation/javascript/examples/geocoding-simple.html