1

所以我最近开始使用 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);
});

}

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

4

2 回答 2

7

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

请在 index.html 中试试这个:

<script src="http://maps.google.com/maps/api/js?sensor=true&libraries=places" type="text/javascript"></script>
于 2013-12-22T08:41:06.050 回答
0

我立即看到了一些错误。例如,“位置”在您的请求变量中拼写错误。

您还应该使用“var map”声明您的地图变量。但这只是风格问题。修复这些并查看它是否有效,然后我们可以排除更多故障。

于 2013-05-07T08:20:41.337 回答