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'機能は実行されません。私はURLの結果を保存し、問題なくそのファイルを使用することもできます。TextSearchは出力を返しませんが(URLは有効です)
私のコードでURLを直接使用できないのはなぜですか?
ありがとうございました。
を使用し、JavaScriptから場所のAPIのテキスト検索にアクセスしたい場合は、完全なコードを送信してください。 – KingRider