0
function getCoffeeLatLon(inpLat, inpLon){
var searchURL = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=coffee&key=AIzaSyCKY43b8fpjLUuagtq1ZdSc477QwFuprew&location=15.7228486,-90.2348";
var firstLat;
var firstLon;
var firstName;
var fullJSON= $.getJSON("https://maps.googleapis.com/maps/api/place/textsearch/json?query=coffee&key=AIzaSyCKY43b8fpjLUuagtq1ZdSc477QwFuprew&location=15.7228486,-90.2348", function(data){
firstLat = data.results[0].geometry.location.lat;
firstLon = data.results[0].geometry.location.lng;
firstName = data.results[0].name;
console.log("checking");
});
var coffeeLatLonName = [firstLat, firstLon, firstName];
return coffeeLatLonName;
}
以上是我的代碼示例。儘管我可以在線訪問Google Maps API URL並查看完整的JSON結果,但在我的代碼中使用它時,它不會運行我的$ .getJSON調用的'sucess'函數。我也可以保存網址的結果並使用該文件而沒有問題。TextSearch不返回輸出(但URL有效)
爲什麼我不能直接在我的代碼中使用URL?
謝謝。
我可以幫助我們,請發送完整的代碼 – KingRider