Google Places Service提供了未定义的错误

Lou*_*ieV 1 google-maps-api-3 google-places

所以我最近开始使用Maps Api v3,当我尝试进行附近搜索时,我得到并且未定义错误.在这条线上var service_places = new google.maps.places.PlacesService(map);

function setupMap (position) {
// console.log(position);
var curLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
// console.log(curLocation);
var mapContainer = document.getElementById('map-container');
var mapOptions = {
    zoom: 13,
    center: curLocation,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    disableDefaultUI: true,
    mapTypeControl: true,
    mapTypeControlOptions: {
        style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
    }
};
map = new google.maps.Map(mapContainer,mapOptions);
var marker = new google.maps.Marker ({
    position: curLocation,
    map: map,
    title: "I am here :)"   
});
getNearMe(curLocation);
}


function getNearMe (curLocation) {
var request = {
    loacation: curLocation,
    radius: '10000',
    types: ['bar', 'night_club']
};
var service_places = new google.maps.places.PlacesService(map);
service_places.nearbySearch(request,function (response,status) {
    console.log(status);
    console.log(response);
});

}
Run Code Online (Sandbox Code Playgroud)

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=<MY-KEY>-fSUI&sensor=false"> </script>

fil*_*vic 6

您应该在google api链接中包含地点库.

请在index.html中尝试:

<script src="http://maps.google.com/maps/api/js?sensor=true&libraries=places" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)