Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Google places nearbySearch()返回无效的\u请求_Javascript_Google Maps_Google Maps Api 3_Google Places Api - Fatal编程技术网

Javascript Google places nearbySearch()返回无效的\u请求

Javascript Google places nearbySearch()返回无效的\u请求,javascript,google-maps,google-maps-api-3,google-places-api,Javascript,Google Maps,Google Maps Api 3,Google Places Api,我有以下代码: if(navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position) { pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); var request = { location: pos,

我有以下代码:

 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);
    });
  }
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(函数(位置){
pos=新的google.maps.LatLng(position.coords.lation,position.coords.longitude);
var请求={
地点:pos,,
半径:500,
类型:['store']
};
infowindow=new google.maps.infowindow();
var service=newgoogle.maps.places.PlacesService(地图);
函数createMarker(place){
var placeLoc=place.geometry.location;
var marker=new google.maps.marker({
地图:地图,
位置:place.geometry.location
});
google.maps.event.addListener(标记'click',函数(){
infowindow.setContent(place.name);
打开(地图,这个);
});
}
函数回调(结果、状态){
if(status==google.maps.places.PlacesServiceStatus.OK){
对于(var i=0;i
nearbySearch返回: “无效的\u请求”、“未找到”、“确定”、“超过\u查询\u限制”、“请求\u被拒绝”、“未知\u错误”、“零\u结果”
但是,当我使用这里给出的坐标而不是当前位置时,它可以正常工作。当我尝试其他coords时,它返回上述错误,有什么问题吗?

此代码似乎工作正常。

您的浏览器不允许使用当前位置可能会出现问题,因为示例中给出的坐标适用于您。查看浏览器的位置设置或尝试其他浏览器。

这段代码对我来说很好。我不知道为什么,但所有这些:pos=new google.maps.LatLng(-33.8665433151.1956316)//示例数据pos=new google.maps.LatLng(52.24083611.015358);//华沙数据pos=new google.maps.LatLng(41.89001,-87.627754);//芝加哥数据返回“无效请求”、“未找到”、“确定”、“超过查询限制”、“请求被拒绝”、“未知错误”、“零结果”,仅使用第一个(示例数据),我在地图上获得了一些标记。我发现错误,设置了标记,但地图仍以皮尔蒙特为中心,因此标记不可见。