使用JavaScript在Google地图中使用Foursquare API

使用JavaScript在Google地图中使用Foursquare API,javascript,google-maps,foursquare,Javascript,Google Maps,Foursquare,我已经尝试在谷歌地图中实现foursquare API,这可以帮助我解决不断出现的错误 function createMarker(location){ var marker = new google.maps.Marker({ map: map, position: location.latlng, title: location.name, animation: google.maps.Animation.DROP }); location.marker =

我已经尝试在谷歌地图中实现foursquare API,这可以帮助我解决不断出现的错误

function createMarker(location){
  var marker = new google.maps.Marker({
   map: map,
  position: location.latlng,
  title: location.name,
  animation: google.maps.Animation.DROP
   });

  location.marker = marker;

    getVenueDetails(location, function(windowContent){
    infoWindow.setContent(windowContent);
    infoWindows.push(infoWindow);
  });
 google.maps.event.addListener(marker, 'click', function() {
    getVenueDetails(location, function(windowContent){
    infoWindow.setContent(windowContent);
    infoWindow.open(map, self);
  });
 });
  }
  var baseUrl = 'https://api.foursquare.com/v2/venues/search?',
  clientId = '*********************************************',
   clientSecret = '*******************************************';

 function getVenueDetails(location, infoWindowCallback) {
 foursquareUrl = baseUrl + '&client_id=' + clientId + '&client_secret=' + clientSecret + '&v=20161207&query=' + Model[location].id + '&ll=11.93,79.82';
 $.getJSON(foursquareUrl)
  .done(function(data){
    var currentVenue = data.response.venues[0];
    var placeName = currentVenue.name;
    var placeAddress = currentVenue.address.formattedAddress;
    var placePhonenos = (currentVenue.contact.formattedPhone === undefined)? 'None': currentVenue.contact.formattedPhone;
   windowContent = '<div id="iw_container"><p><strong>Name: </strong>' + placeName+ '</p>' +
                '<p><strong>Address: </strong>  ' + placeAddress + '</p>' +
                '<p><strong>Phone: </strong>' + placePhonenos + '</p></div>';
   infoWindowCallback(windowContent);
  }).fail(function(error){
    infoWindow.setContent('Fail to connect to Foursquare: ' + error);
  }
  );
   }
函数createMarker(位置){
var marker=new google.maps.marker({
地图:地图,
位置:location.latlng,
标题:location.name,
动画:google.maps.animation.DROP
});
location.marker=标记;
getVenueDetails(位置、功能(windowContent){
setContent(windowContent);
推送(infoWindow);
});
google.maps.event.addListener(标记'click',函数(){
getVenueDetails(位置、功能(windowContent){
setContent(windowContent);
信息窗口。打开(地图,自我);
});
});
}
var baseUrl=https://api.foursquare.com/v2/venues/search?',
clientId='*********************************************************************************',
clientSecret='***********************************************************************';
函数getVenueDetails(位置,infoWindowCallback){
foursquareUrl=baseUrl+'&client_id='+clientId+'&client_secret='+clientSecret+'&v=20161207&query='+Model[location].id+'&ll=11.93,79.82';
$.getJSON(foursquareUrl)
.完成(功能(数据){
var currentVincement=data.response.vinces[0];
var placeName=currentVincement.name;
var placeAddress=CurrentVincement.address.formattedAddress;
变量placePhonenos=(CurrentVincement.contact.formattedPhone==未定义)?“无”:CurrentVincement.contact.formattedPhone;
windowContent='名称:'+placeName+'

'+ “地址:”+placeAddress+”

'+ “电话:”+placePhonenos+”

; infoWindowCallback(windowContent); }).失败(功能(错误){ infoWindow.setContent('无法连接到Foursquare:'+错误); } ); }
这是我的报告。。。
我在主要位于模型[location].id.中的API节中遇到错误。。我得到的“id”未定义错误。。。谢谢你的帮助

我没有看到模型类中定义的
id
。此外,您应该将场馆名称传递给Foursquare search
query
参数,而不是lat/lng。您应该将
Model[location].id
更改为
Model[name]

尝试替换此行:

foursquareUrl = baseUrl + '&client_id=' + clientId + '&client_secret=' + clientSecret + '&v=20161207&query=' + Model[location].id + '&ll=11.93,79.82';
为此:

foursquareUrl = baseUrl + '&client_id=' + clientId + '&client_secret=' + clientSecret + '&v=20161207&query=' + Model[name] + '&ll=11.93,79.82';