[英]Google Maps API javascript: nearbysearch callback function not calling
I followed Google's documentation closely, but for some reason my callback function isn't being called. 我密切关注了Google的文档,但由于某些原因我的回调函数没有被调用。 I stripped everything down so that it should just show an alert, and it doesn't.
我把所有东西都剥下来,以便它只是显示一个警报,但事实并非如此。 I've tried searching for the problem, but it's so simple I can't even figure out what to search for.
我已经尝试过搜索问题了,但它很简单,我甚至无法弄清楚要搜索的内容。 Any thoughts?
有什么想法吗?
service = new google.maps.places.PlacesService(myMap);
service.nearbySearch(request, callback);
// this displays
alert("TESTING");
...
function callback(results, status) {
// this does not display
alert("WHY DOESNT THIS DISPLAY?");
}
I've also tried this: 我也试过这个:
service = new google.maps.places.PlacesService(myMap);
service.nearbySearch(request, function callback(results, status) {
alert("WHY DOESNT THIS WORK?");
});
Take a look at the console, you will see this warning: 看一下控制台,你会看到这个警告:
Warning: you have included the Google Maps API multiple times on this page. 警告:您已在此页面上多次添加Google Maps API。 This may cause unexpected errors.
这可能会导致意外错误。
That's what you got, an unexpected error. 这就是你得到的,一个意想不到的错误。
You have included the API 3 times: 您已将API包含3次:
line#140 线#140
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCx9FbzJ-0Ck8gts9oq11nAZU7F6LjLq8Y&sensor=false">
</script>
line#146: 线#146:
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>
line 636: 第636行:
<script type='text/javascript' src='http://maps.google.com/maps/api/js?sensor=false&ver=1.0.0'></script>
Remove the scripts from line#140 and line#636 and you will see both alerts 从第140行和第636行删除脚本,您将看到两个警报
function callback(results, status) {
应该:
function (results, status) {
Is your request object/string valid? 您的请求对象/字符串是否有效? You're not setting
request
to anything in this snippet: googleplaces probably won't fire your callback if you didn't make a real requst. 您没有在此代码段中为任何内容设置
request
:如果您没有真正request
,googleplaces可能不会触发您的回调。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.