次の2つのファイルを作成しました。
code.gs
function doGet() {
var html = HtmlService.createHtmlOutputFromFile('html.html');
return html;
}
html.html
<html>
<body>
<p id="messaging">Click the button to get your coordinates:</p>
<button onclick="getLocation()">Where am I</button>
<script>
var message=document.getElementById("messaging");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
message.innerHTML="Geolocation is not supported.";
}
}
function showPosition(position) {
message.innerHTML="Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude;
}
</script>
</body>
</html>
公開されたURLを呼び出すと、期待されるメッセージとボタンが表示されます。ボタンをクリックすると、「ジオロケーションはサポートされていません」という失敗メッセージが表示されます。html.htmlをファイルに保存してブラウザで開くと、期待どおりに機能します。
何か案は?