前提・実現したいこと
html内の以下のデータをgasに値を受け渡ししたい。
①Formの値
②jsのnavigator.geolocation.getCurrentPositionの緯度と経度の値(
gasとhtmlをベースに現在地の緯度経度情報を含んだ、タイムカードを作成したいと考えています。
gas→html呼び出し→form内容をgasへ値の受け渡しまではできているのですが、
jsで取得した緯度と経度の値をどのようにgasへ渡せば良いのか悩んでいます。
よろしくお願いいたします。
■ ■ ■ ■ ■ ■ html側 ■ ■ ■ ■ ■ ■
html
1<!DOCTYPE html> 2<html> 3 <head> 4 <base target="_top"> 5 <script> 6 function preventFormSubmit() { 7 var forms = document.querySelectorAll('form'); 8 for (var i = 0; i < forms.length; i++) { 9 forms[i].addEventListener('submit', function(event) { 10 event.preventDefault(); 11 }); 12 } 13 } 14 window.addEventListener('load', preventFormSubmit); 15 16 function handleFormSubmit(formObject) { 17 google.script.run.withSuccessHandler().processForm(formObject); 18 } 19 20 // 現在地取得処理 21 function getPosition() { 22 // 現在地を取得 23 navigator.geolocation.getCurrentPosition( 24 function(position) { 25 var ido = position.coords.latitude 26 var keido =position.coords.longitude 27 } 28 } 29 </script> 30 31</head> 32<body> 33<div class = container> 34 <form onsubmit="handleFormSubmit(this)"> 35 <table align = center class = teble1> 36 <tbody> 37 38 <tr> 39 <th>項目1</th> 40 <td> 41 <input type= text name="i1" > 42 </td> 43 </tr> 44 45 </table><!-- end table --> 46 <input type="submit" value="送信" > 47 </form> 48 </div> 49</body> 50</html>
■ ■ ■ ■ ■ ■ gs側 ■ ■ ■ ■ ■ ■
1function doGet() { 2 var html = HtmlService.createTemplateFromFile('report'); 3 return html.evaluate(); 4} 5 6function processForm(formObject) { 7 'フォーム内のデータ' 8 var val2 = formObject.i1; //項目1 9 10 11 var ss = SpreadsheetApp.openById("***"); 12 var sh = ss.getSheetByName("***"); 13 14 'Row/Column' 15 var lastRow = sh.getLastRow(); 16 var lastColumn = sh.getLastColumn(); 17 18 var now = new Date(); 19 sh.getRange(lastRow+1,1).setValue(Utilities.formatDate(now, 'Asia/Tokyo', 'yyyy/MM/dd HH:mm:ss')); 20 sh.getRange(lastRow+1,2).setValue(val1); 21} 22 23
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。