2019年12月4日水曜日

FileMakerでGoogle Route Mapを表示、Google Maps JavaScript API v3使用

FileMakerでGoogle Route Mapを表示
距離を取得
所要時間を取得
動作検証
Windows 10
FileMaker 13,14,15,16,17,18

Mac OS 10.13.3
FileMaker Pro 18

iOS13
FileMaker Go 18

サンプルファイル
GRouteMap_Limited.zip(無料)管理者権限無し
https://fm-aid.stores.jp/items/5de7b105b080e01d0f22c8d9


有料サンプル
ご支援頂ける場合、ご購入頂けると幸いです。
GRouteMap_Unlimited.zip(500円)管理者権限あり
https://fm-aid.stores.jp/items/5de7b36cd20039790920e1d6


Google Maps JavaScript API
APIキー取得方法は、以下を参照して下さい。
https://qbxxdp.blogspot.com/2019/11/filemakergoogle-mapgoogle-maps.html


Google Route Map を利用するには、「Maps JavaScript API」と「Directions API」を有効にする必要があります。
「APIキー取得方法」ですでに「Maps JavaScript API」は有効になっていると思います。
※Google Route Mapでは「Geocoding API」はいりません。


「API の制限」を設定している場合は、「Directions API」も追加。


APIキーをコピー

FileMaker
[歯車]アイコンをクリック


APIキーを貼り付け

「出発」「目的地」を入力し、[Go]ボタンをクリックでルートマップが表示されます




2019年11月30日土曜日

WEBフォームの値をイイ感じのJSONにする。JSONからWEBフォームへ再入力。

WEBフォームの値をイイ感じのJSONにする。
JSONからWEBフォームへ再入力可能で、WEBフォームのテスト入力に便利。

サイトにjQueryが読み込まれている必要があります。

自社サイトでWEBフォームをPOSTする場合に活用したり、
WEBフォームの入力テストで何度も再入力したり.....

https://www.1-firststep.com/」さんのサンプルフォームをお借りして動作を見ていきましょう。
Google ChromeでサンプルWEBフォームを開きます。
https://www.1-firststep.com/samplephp/mailform-v7.2.1/index.html
フォームに入力。


[F12]キーを押して、デベロッパーツールを開く
Consoleに以下のJavaScriptを貼り付けて実行。

function create_json(obj_form) {
    var items = Get_checkbox_radio_name(obj_form);
    var serialize = obj_form.serializeArray();
    var json_data = {};
    for (idx in serialize) {
        var key = serialize[idx]["name"];
        var value = serialize[idx]["value"];
        value = value.replace(/\n\r/g, '\n').replace(/\r\n/g, '\n').replace(/\n/g, '\n').replace(/\t/g, '\t').replace(/\\/g, '\\').replace(/\"/g, '\"');
        var _index = items.indexOf(key);
        if (_index >= 0) {
            var arr = [];
            if (json_data[key]) { arr = json_data[key]; }

            arr.push(value);
            json_data[key] = arr;

        } else {
            json_data[key] = value;
        }
    }
    return json_data;
}

function Get_checkbox_radio_name(obj_form) {
    var _array = [];
    var _obj = $(obj_form).find("select,:checkbox,:radio");
    _obj.each(function (index, element) {
        _array.push($(element).attr('name'));
    });
    return _array;
}

var data_obj = create_json($('form'));
JSON.stringify(data_obj);

赤枠部分に作成されたJSONが、表示されます。
※自社サイトでWEBフォームをPOSTする場合にも扱いやすい形式になっていると思います。



JSONを使ってWEBフォームへ再入力。

以下のJavaScriptの {JSON} 部分に上記の JSONデータを入力し、再入力用のJavaScriptを作成

var data_obj={JSON};

$.each(data_obj, function (index, value) {
    if ($.isArray(value) === false) {
        $('*[name="' + index + '"]').val(value);
    }
    if ($.isArray(value) && $.isPlainObject(value) === false) {
        $('*[name="' + index + '"]').val(value);
    }
    if ($.isArray(value)) {
        $.each(value, function (index, value) {
            var n = index;
            if ($.isPlainObject(value)) {
                $.each(value, function (index, value) {
                    $('*[name="' + index + '"]').eq(n).val(value);
                });
            }
        });
    }
});

var data_obj={
    "company": "会社名",
    "name_1": "日本",
    "name_2": "太郎",
    "read_1": "にほん",
    "read_2": "たろう",
    "mail_address": "abc@d.com",
    "mail_address_confirm": "abc@d.com",
    "gender": [
        "男性"
    ],
    "target": [
        "女性"
    ],
    "postal": "100-0000",
    "address": "東京都千代田区",
    "phone": "00-0000-0000",
    "schedule": "2019/11/30 14:20",
    "product": [
        "iPhone6"
    ],
    "use": [
        "iPhone6s"
    ],
    "kind[]": [
        "WEBサイトについて",
        "キャンペーンについて",
        "ご意見・ご要望"
    ],
    "response[]": [
        "メールでの返信を希望"
    ],
    "contents": "お問い合わせの内容",
    "message": "愛の告白"
};

$.each(data_obj, function (index, value) {
    if ($.isArray(value) === false) {
        $('*[name="' + index + '"]').val(value);
    }
    if ($.isArray(value) && $.isPlainObject(value) === false) {
        $('*[name="' + index + '"]').val(value);
    }
    if ($.isArray(value)) {
        $.each(value, function (index, value) {
            var n = index;
            if ($.isPlainObject(value)) {
                $.each(value, function (index, value) {
                    $('*[name="' + index + '"]').eq(n).val(value);
                });
            }
        });
    }
});

Google ChromeのデベロッパーツールのConsoleにJavaScriptを貼り付けて実行。
WEBフォームに値が再入力されます。


お気に入りにJavaScriptスキームとして登録しておけば、WEBフォーム入力テスト時に1クリックで再入力が可能です。



2019年11月17日日曜日

FileMakerでGoogle Mapを表示、Google Maps JavaScript API v3使用|作成方法

FileMakerでGoogle Mapを表示
Google Maps JavaScript API v3 使用
APIキー取得方法
https://qbxxdp.blogspot.com/2019/11/filemakergoogle-mapgoogle-maps.html

動作検証
Windows 10
FileMaker 13,14,15,16,17,18

Mac OS 10.13.3
FileMaker Pro 18

iOS13
FileMaker Go 18

サンプルファイル
GMap_Limited.zip(無料)管理者権限無し
https://fm-aid.stores.jp/items/5dd0e28063794452d5012237

作るのが面倒な場合、有料サンプルをどうぞ。
また、ご支援頂ける場合、ご購入頂けると幸いです。
GMap_Unlimited.zip(500円)管理者権限あり
https://fm-aid.stores.jp/items/5dd0ec45a3423d5602e165c2




FileMaker
テーブル:



レイアウト:


リレーション:

スクリプト:
変数を設定 [ $map.js; 値:" var address= '{{address}}'; var Zoom = {{Zoom}}; var myLatlng; function codeAddress() { var geocoder = new google.maps.Geocoder(); geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { myLatlng=results[0].geometry.location; initialize(); } else { alert('Geocode was not successful for the following reason: ' + status); } }); } function initialize() { var mapOptions = { zoom: Zoom, center: myLatlng }; var map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions); var marker = new google.maps.Marker({ position: myLatlng, map: map, title: address }); } " /*参考:Geocoding Service   |   Google Maps JavaScript API   |   Google Developers : https://developers.google.com/maps/documentation/javascript/geocoding*/ ]
変数を設定 [ $map.js; 値:Substitute ( $map.js ; [ "{{address}}" ; GMap::address ] ; [ "{{Zoom}}" ; GMap::Zoom ] ) ]
変数を設定 [ $html; 値:Let([html= "data:text/html;charset=utf-8, <html> <head> <meta http-equiv='content-type' content='text/html; charset=utf-8'/> <meta http-equiv='X-UA-Compatible' content='IE=edge'/> <style type='text/css'> html, body, #map_canvas { width: 100%; height: 100%; margin: 0; padding: 0; } body { border:0;padding:0;margin:0;overflow:hidden; font-size:75%; font-family: 'メイリオ', Meiryo ; } #map_canvas { position: relative; } </style> <script type='text/javascript' src='http://maps.google.com/maps/api/js?key={api_key}'></script> <script type='text/javascript'>{map.js}</script> </head> <body onload='codeAddress()'> <div id='map_canvas'></div> </body></html>" ]; Substitute ( html ; ["{api_key}" ; google_project::api_Key] ; ["{map.js}" ; $map.js] ) ) ]
Web ビューアの設定 [ オブジェクト名: "WEB1"; URL: $html ]