2013-12-23 216 views
0

我需要了解Google地點的詳細信息。 我需要OPENING_HOURS所以我寫這篇文章:從google地方獲取詳細信息

等我的代碼添加請求到位,服務和getDetails功能

markers = []; 
var bounds = new google.maps.LatLngBounds(); 
for (var i = 0, place; place = places[i]; i++) { 
    var image = { 
     url: place.icon, 
     size: new google.maps.Size(71, 71), 
     origin: new google.maps.Point(0, 0), 
     anchor: new google.maps.Point(17, 34), 
     scaledSize: new google.maps.Size(25, 25) 
    }; 
    //CODE THAT I WRITE TO GET DETAILS FOR PLACE 
    var request = { 
     reference: place.reference 
    }; 
    var service = new google.maps.places.PlacesService(map); 
    service.getDetails(request, function (place, status) { 
     var open = ''; 
     try { 
      open = place.opening_hours.periods[1].open.time; 
     } catch (e) { 
      open = 'No work time'; 
     } 
     var otvoreno = place.openNow + "</br>" + place.name; 
     // Create a marker for each place. 
     var marker = new MarkerWithLabel({ 
      map: map, 
      icon: image, 
      title: place.name, 
      position: place.geometry.location, 
      labelContent: open, 
      labelClass: "labels", // the CSS class for the label 
      labelStyle: { 
       opacity: 0.75 
      }, 
      labelAnchor: new google.maps.Point(22, 0) 
     }); 
    }); 
    markers.push(marker); 
    bounds.extend(place.geometry.location); 
} 

,但我得到的錯誤:

Uncaught TypeError: Cannot read property 'openNow' of null 

我怎麼能解決這個問題?

回答