我已经尝试在谷歌地图中实施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);
}
);
}
这是我的回购map ... 我在API部分得到错误主要是在模型[location] .id ..我得到&#34; id&#34;未定义错误...感谢任何帮助..
答案 0 :(得分:0)
我没有在您的Model类中定义id
。此外,您应该将场地名称传递给Foursquare搜索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';