简体   繁体   English

Google Maps API javascript:nearbysearch回调函数未调用

[英]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&#038;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.

相关问题 使用Google Maps API nearBysearch有多种类型 - Using Google maps API nearBysearch with multiple types 从另一个函数调用一个函数 JavaScript Google Maps API - Calling a function from another function JavaScript Google Maps API 在Google Maps API地方信息库中使用邻近搜索不起作用 - Using NearbySearch in Google Maps API Places Library not working Google Maps Api:使用 nearSearch() 有 20 个结果,但使用 PlacesService() 只有 9 个结果 - Google Maps Api : 20 results with nearbySearch() but only 9 with PlacesService() Javascript回调和Google Maps API问题 - Javascript callback and google maps api question Office getFileAsync函数的JavaScript API未调用回调 - JavaScript API for Office getFileAsync Function is not calling callback 在InfoWindow中调用JavaScript函数(Google Maps) - Calling a JavaScript function within an InfoWindow (Google Maps) Maps API Javascript函数调用错误 - Maps API Javascript function calling fault 从附近搜索获取PlaceID并显示在标记InfoWindow(JS Google Maps API)中 - Get PlaceID from nearbySearch and display in a marker InfoWindow ( JS Google Maps API ) JS通过调用或不调用函数的反应不同(使用了Google Maps API) - JS reacts differently by calling or not calling a function (google maps api is used)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM