0

尝试从 Google Places API 中提取数据,但在阅读文档后无法正常工作。我一定错过了什么,有人可以帮忙吗?

<script>

    var request = {
        location: new google.maps.LatLng(-33.8665433,151.1956316), 
        radius: '500',
        types: ['store']
    };

    var service = new google.maps.places.PlaceService(map);
    service.nearbySearch(request, callback);

    function callback(results, status) {
        for(var i = 0; i < results.length; i++){
            document.write(results[i] + '<br/>'); 
        }
    };      


    </script> 

通过将代码更改为此,我得到了错误:

    var request = {
        location: new google.maps.LatLng(-33.8665433,151.1956316), 
        radius: '500',
        types: ['store']
    };


    service = new google.maps.places.PlacesService(map);
    service.nearbySearch(request, callback);
     if (status == google.maps.places.PlacesServiceStatus.OK){
    function callback(results, status) {
        for(var i = 0; i < 7; i++){
            document.write(results[i] + 'test <br/>'); 
        }
        }
    };      


    </script>

但是它仍然没有返回任何数据。请有人帮忙。谢谢!!!

4

1 回答 1

0

文档的示例页面上有 Google Maps JavaScript API v3 - Places Library 的代码示例。

您可以在此处查看Place Library Nearby Search 的工作示例。

于 2013-01-02T06:02:18.170 回答