【问题标题】:Google places nearbySearch() returns invalid_requestGoogle 地点附近搜索()返回 invalid_request
【发布时间】:2013-09-06 14:39:04
【问题描述】:

我有以下代码:

 if(navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
        pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

        var request = {
            location: pos,
            radius: 500,
            types: ['store']
        };

        infowindow = new google.maps.InfoWindow();
        var service = new google.maps.places.PlacesService(map);

        function createMarker(place) {
          var placeLoc = place.geometry.location;
          var marker = new google.maps.Marker({
            map: map,
            position: place.geometry.location
          });

          google.maps.event.addListener(marker, 'click', function() {
            infowindow.setContent(place.name);
            infowindow.open(map, this);
          });
        }

        function callback(results, status) {
          if (status == google.maps.places.PlacesServiceStatus.OK) {
            for (var i = 0; i < results.length; i++) {
              createMarker(results[i]);
            }
          }
        }
        service.nearbySearch(request, callback);
    });
  }

nearbySearch 返回: “INVALID_REQUEST”、“NOT_FOUND”、“OK”、“OVER_QUERY_LIMIT”、“REQUEST_DENIED”、“UNKNOWN_ERROR”、“ZERO_RESULTS” 但是当我使用https://developers.google.com/maps/documentation/javascript/places 此处给出的坐标而不是当前位置时,它可以正常工作。当我尝试其他坐标时,它返回上述错误,有什么问题?

【问题讨论】:

  • 这段代码对我来说很好。

标签: javascript google-maps google-maps-api-3 google-places-api


【解决方案1】:

这段代码似乎运行良好。
您的浏览器可能存在问题,不允许使用您当前的位置,因为示例中给出的坐标对您有用。查看浏览器的位置设置或尝试其他浏览器。

【讨论】:

  • 我不知道为什么,但所有这些:pos = new google.maps.LatLng(-33.8665433, 151.1956316); //示例数据 pos = new google.maps.LatLng(52.240836, 21.015358); // 华沙数据 pos = new google.maps.LatLng(41.89001, -87.627754); // 芝加哥数据返回“INVALID_REQUEST”、“NOT_FOUND”、“OK”、“OVER_QUERY_LIMIT”、“REQUEST_DENIED”、“UNKNOWN_ERROR”、“ZERO_RESULTS”,并且仅使用第一个(示例数据),我的地图上有一些标记.
  • 我发现错误,标记已设置,但地图仍以 pyrmont 为中心,因此标记不可见。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-09
  • 1970-01-01
  • 1970-01-01
  • 2016-03-05
  • 1970-01-01
相关资源
最近更新 更多