{"id":315,"date":"2021-03-25T10:24:42","date_gmt":"2021-03-25T01:24:42","guid":{"rendered":"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=315"},"modified":"2021-03-25T14:06:59","modified_gmt":"2021-03-25T05:06:59","slug":"blazor%e3%81%8b%e3%82%89geolocation-api%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b","status":"publish","type":"post","link":"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=315","title":{"rendered":"blazor\u304b\u3089geolocation API\u3092\u4f7f\u3063\u3066\u307f\u308b"},"content":{"rendered":"\n<p>HTML5\u3092\u30b5\u30dd\u30fc\u30c8\u3057\u3066\u3044\u308b\u30d6\u30e9\u30a6\u30b6\u3067\u306f\u3001GPS\u7b49\u3092\u4f7f\u7528\u3057\u3066\u3001\u4f4d\u7f6e\u60c5\u5831\u3092\u5f97\u308b\u3001geolocation API\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3042\u308b\u3002<\/p>\n\n\n\n<p>geolocation API\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u95a2\u6570\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u3002<\/p>\n\n\n\n<p><strong>geolocation.getCurrentPosition<\/strong>-\u4f4d\u7f6e\u60c5\u5831\u30921\u56de\u3060\u3051\u53d6\u5f97\u3059\u308b\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-js\" data-file=\"getCurrentPosition\" data-lang=\"JavaScript\"><code>\/\/\n\/\/\tloc:\u4f4d\u7f6e\u60c5\u5831\n\/\/\terr:\u30a8\u30e9\u30fc\u60c5\u5831\n\/\/\nnavigator.geolocation.getCurrentPosition(\n    function(loc) {}\t\/\/ \u4f4d\u7f6e\u60c5\u5831\u53d6\u5f97\u6210\u529f\u6642\u51e6\u7406\n    function(err) {}\t\/\/ \u4f4d\u7f6e\u60c5\u5831\u53d6\u5f97\u5931\u6557\u6642\u51e6\u7406\n);<\/code><\/pre><\/div>\n\n\n\n<p><strong>geolocation.geolocation.watchPosition<\/strong>-\u4f4d\u7f6e\u60c5\u5831\u304c\u5909\u308f\u308b\u305f\u3073\u306b\u6307\u5b9a\u95a2\u6570\u3092\u547c\u3073\u51fa\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-js\" data-file=\"watchPosition\" data-lang=\"JavaScript\"><code>\/\/\n\/\/\tloc:\u4f4d\u7f6e\u60c5\u5831\n\/\/\terr:\u30a8\u30e9\u30fc\u60c5\u5831\n\/\/\nwatchid = navigator.geolocation.watchPosition(\n    function(e) {},\t\t\/\/ \u4f4d\u7f6e\u60c5\u5831\u53d6\u5f97\u6210\u529f\u6642\u51e6\u7406\n    function(e) {}\t\t\/\/ \u4f4d\u7f6e\u60c5\u5831\u53d6\u5f97\u5931\u6557\u6642\u51e6\u7406\n);\n<\/code><\/pre><\/div>\n\n\n\n<p><strong>geolocation.clearWatch<\/strong>-watchPosition\u306e\u505c\u6b62<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-js\" data-file=\"clearWatch\" data-lang=\"JavaScript\"><code>\/\/\n\/\/\twatchid:watchPosition\u306e\u623b\u308a\u5024\n\/\/\nnavigator.geolocation.clearWatch(watchid);\n<\/code><\/pre><\/div>\n\n\n\n<span style=\"font-weight:bold\">\u4f4d\u7f6e\u60c5\u5831\u30d1\u30e9\u30e1\u30fc\u30bf<\/span>\n        <table style=\"border-style:solid;border-color:darkgray;border-width:1px;border-collapse:collapse\">\n            <tr>\n                <td rowspan=\"8\" style=\"vertical-align: middle;border-style:solid;border-width:1px;border-color:darkgray;background-color:aliceblue;\">coords<\/td>\n<td colspan=\"2\"style=\"border-style:solid;border-width:1px;border-color:darkgray\">\u4f4d\u7f6e\u60c5\u5831<\/td>\n            <\/tr>\n            <tr>\n                <td style=\"border-style:solid;border-width:1px;border-color:darkgray;background-color:aliceblue;\">latitude<\/td><td style=\"border-style:solid;border-width:1px;border-color:darkgray\">\u7def\u5ea6<\/td>\n            <\/tr>\n            <tr>\n                <td style=\"border-style:solid;border-width:1px;border-color:darkgray;background-color:aliceblue;\">longitude<\/td><td style=\"border-style:solid;border-width:1px;border-color:darkgray\">\u7d4c\u5ea6<\/td>\n            <\/tr>\n            <tr>\n                <td style=\"border-style:solid;border-width:1px;border-color:darkgray;background-color:aliceblue;\">altitude<td style=\"border-style:solid;border-width:1px;border-color:darkgray\">\u9ad8\u5ea6<\/td>\n            <\/tr>\n            <tr>\n                <td style=\"border-style:solid;border-width:1px;border-color:darkgray;background-color:aliceblue;\">accuracy<\/td><td style=\"border-style:solid;border-width:1px;border-color:darkgray\">\u7def\u5ea6\u30fb\u7d4c\u5ea6\u306e\u8aa4\u5dee<\/td>\n            <\/tr>\n            <tr>\n                <td style=\"border-style:solid;border-width:1px;border-color:darkgray;background-color:aliceblue;\">altitudeAccuracy<\/td><td style=\"border-style:solid;border-width:1px;border-color:darkgray\">\u9ad8\u5ea6\u306e\u8aa4\u5dee<\/td>\n            <\/tr>\n            <tr>\n                <td style=\"border-style:solid;border-width:1px;border-color:darkgray;background-color:aliceblue;\">heading<\/td><td style=\"border-style:solid;border-width:1px;border-color:darkgray\">\u65b9\u89d2(0.0\uff5e360.0)<\/td>\n            <\/tr>\n            <tr>\n                <td style=\"border-style:solid;border-width:1px;border-color:darkgray;background-color:aliceblue;\">speed<\/td><td style=\"border-style:solid;border-width:1px;border-color:darkgray\">\u30b9\u30d4\u30fc\u30c9<\/td>\n            <\/tr>\n            <tr>\n                <td style=\"border-style:solid;border-width:1px;border-color:darkgray;background-color:aliceblue;\">timestamp<\/td><td colspan=\"2\" style=\"border-style:solid;border-width:1px;border-color:darkgray\">\u30bf\u30a4\u30e0\u30b9\u30bf\u30f3\u30d7<\/td>\n            <\/tr>\n        <\/table><\/br>\n<span style=\"font-weight:bold\">\u30a8\u30e9\u30fc\u60c5\u5831\u30d1\u30e9\u30e1\u30fc\u30bf<\/span>\n<table style=\"border-style:solid;border-color:darkgray;border-width:1px;border-collapse:collapse\">\n<tr>\n<td style=\"border-style:solid;border-width:1px;border-color:darkgray;background-color:aliceblue;\" rowspan=\"5\">code<\/td><td style=\"border-style:solid;border-width:1px;border-color:darkgray;\" colspan=\"2\">\u30a8\u30e9\u30fc\u30b3\u30fc\u30c9<\/td>\n<\/tr>\n<tr>\n<td style=\"border-style:solid;border-width:1px;border-color:darkgray;\">0<\/td>\n<td style=\"border-style:solid;border-width:1px;border-color:darkgray;\">\u4e0d\u660e\u306a\u30a8\u30e9\u30fc<\/td>\n<\/tr>\n<tr>\n<td style=\"border-style:solid;border-width:1px;border-color:darkgray;\">1<\/td>\n<td style=\"border-style:solid;border-width:1px;border-color:darkgray;\">\u4f4d\u7f6e\u60c5\u5831\u306e\u53d6\u5f97\u3092\u62d2\u5426\u3055\u308c\u305f<\/td>\n<\/tr>\n<tr>\n<td style=\"border-style:solid;border-width:1px;border-color:darkgray;\">2<\/td>\n<td style=\"border-style:solid;border-width:1px;border-color:darkgray;\">\u4f4d\u7f6e\u60c5\u5831\u3092\u53d6\u5f97\u3067\u304d\u306a\u3044<\/td>\n<\/tr>\n<tr>\n<td style=\"border-style:solid;border-width:1px;border-color:darkgray;\">3<\/td>\n<td style=\"border-style:solid;border-width:1px;border-color:darkgray;\">\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8<\/td>\n<\/tr>\n<tr>\n<td style=\"border-style:solid;border-width:1px;border-color:darkgray;background-color:aliceblue;\">message<\/td><td style=\"border-style:solid;border-width:1px;border-color:darkgray;\" colspan=\"2\">\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8<\/td>\n<\/tr>\n\n<\/table>\n\n\n\n<p>\u6298\u89d2\u3053\u306e\u3088\u3046\u306aAPI\u304c\u3042\u308b\u306e\u3067\u3001blazor\u304b\u3089\u547c\u3073\u51fa\u3057\u3066\u307f\u305f\u3044\u3002\u305f\u3060\u3001getCurrentPosition\u95a2\u6570\u3084watchPosition\u95a2\u6570\u306e\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\u304c\u5fc5\u8981\u306b\u306a\u308b\u306e\u3067\u3001\u305d\u3053\u304b\u3089\u3001C#\u30b3\u30fc\u30c9\u3092\u547c\u3073\u51fa\u3059\u3088\u3046\u306b\u3059\u308b\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-js\" data-file=\"JS\u5074\" data-lang=\"JavaScript\"><code>var GPSLib = {\n\t\u30fb\u30fb\u30fb\n\tGetPosition : function(helper,complete,errorhandler) {\n\t    navigator.geolocation.getCurrentPosition(\n\t        function(e) {\n\t            \/\/ \u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u4f5c\u6210(e\u3092\u305d\u306e\u307e\u307e\u6e21\u3057\u3066\u3082\u30ad\u30e3\u30b9\u30c8\u3055\u308c\u306a\u3044\u306e\u3067\u30fb\u30fb\u30fb)\n\t            var prm = {\n\t                coords: {\n\t                    latitude: e.coords.latitude,\n\t                    longitude: e.coords.longitude,\n\t                    altitude: e.coords.altitude != null ? e.coords.altitude : 0,\n\t                    accuracy: e.coords.accuracy != null ? e.coords.accuracy : 0,\n\t                    altitudeAccuracy: e.coords.altitudeAccuracy != null ? e.coords.altitude : 0,\n\t                    heading: e.coords.heading != null ? e.coords.heading : 0,\n\t                    speed: e.coords.speed != null ? e.coords.speed : 0\n\t                },\n\t                timestamp: e.timestamp\n\t            };\n\t            \/\/ C#\u30b3\u30fc\u30c9\u306e\u547c\u51fa\u3057\n\t            helper.invokeMethodAsync(complete,prm);\n\t        },\n\t        function(e) {\n\t            \/\/ \u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u4f5c\u6210(e\u3092\u305d\u306e\u307e\u307e\u6e21\u3057\u3066\u3082\u30ad\u30e3\u30b9\u30c8\u3055\u308c\u306a\u3044\u306e\u3067\u30fb\u30fb\u30fb)\n\t            var prm = {\n\t\t\t\t\tcode: e.code,\n\t\t\t\t\tmessage: e.message\n\t\t\t\t};\n\t            \/\/ C#\u30b3\u30fc\u30c9\u306e\u547c\u51fa\u3057\n\t\t\t\thelper.invokeMethodAsync(errorhandler,prm);\n\t        }\n\t    )\n\t},\n\u30fb\u30fb\u30fb\n};\n<\/code><\/pre><\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-csharp\" data-file=\"C#\u5074\" data-lang=\"C#\"><code>\/\/ \u4f4d\u7f6e\u60c5\u5831(\u4e00\u5fdc\u3001\u3059\u3079\u3066\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u5f97\u3089\u308c\u308b\u3088\u3046\u306b\u3057\u305f)\npublic class GeoInfo {\n    public Coords coords { get; set; }\n    public long timestamp { get; set; }\n}\npublic class Coords {\n    public double latitude {get; set;}\t\/\/ \u7def\u5ea6\n    public double longitude {get; set;}\t\/\/ \u7d4c\u5ea6\n    public double altitude { get; set; }\t\/\/ \u9ad8\u5ea6\n    public double accuracy\t{get; set;} \/\/ \u7def\u5ea6\u30fb\u7d4c\u5ea6\u306e\u8aa4\u5dee\n    public double altitudeAccuracy {get; set;}\t\/\/ \u9ad8\u5ea6\u306e\u8aa4\u5dee\n    public double heading {get; set; }\t\/\/ \u65b9\u89d2\uff080.0\uff5e360.0\uff09\n    public double speed  { get; set; } \/\/ \u30b9\u30d4\u30fc\u30c9\n}\n\/\/ \u30a8\u30e9\u30fc\u60c5\u5831\npublic class GeoError {\n\tpublic int code { get; set; }\n\tpublic string message { get; set; }\n}\n\n\/\/ \u4f4d\u7f6e\u60c5\u5831\u53d6\u5f97\u5b8c\u4e86\u6642\u51e6\u7406\n[JSInvokable]\npublic async Task OnGetPositionComplete(GeoInfo e) {\n    Latitude = e.coords.latitude;\n    Longitude = e.coords.longitude;\n    Orient = e.coords.heading;\n\t\u30fb\u30fb\u30fb\n    this.StateHasChanged();\n}\n\n\/\/ \u4f4d\u7f6e\u60c5\u5831\u53d6\u5f97\u30a8\u30e9\u30fc\u6642\u51e6\u7406\n[JSInvokable]\npublic void OnGetPositionFail(GeoError e) {\n\tErrorMessage = $&quot;\u4f4d\u7f6e\u60c5\u5831\u53d6\u5f97\u30a8\u30e9\u30fc\uff1a{e.code} - {e.message}&quot;;\n\tthis.StateHasChanged();\n}\n\n\u30fb\u30fb\u30fb\n\t\/\/ GetPosition\u306e\u547c\u51fa\u3057\n\tawait JSRuntime.InvokeVoidAsync(\n\t    &quot;GPSLib.GetPosition&quot;,\n\t    DotNetObjectReference.Create(this),\n\t    &quot;OnGetPositionComplete&quot;,&quot;OnGetPositionFail&quot;);\n\t);\n<\/code><\/pre><\/div>\n\n\n\n<p>Google\u3084Bing\u7b49\u306eMAP API\u3068\u7d44\u307f\u5408\u308f\u305b\u308b\u3068\u3001\u30b9\u30de\u30db\u3084\u30bf\u30d6\u30ec\u30c3\u30c8\u7528\u306b\u7d50\u69cb\u9762\u767d\u3044\u30a2\u30d7\u30ea\u304c\u7c21\u5358\u306b\u4f5c\u6210\u3067\u304d\u308b\u3002(\u6b69\u3044\u305f\u5834\u6240\u306e\u30c8\u30ec\u30fc\u30b9\u3084\u73fe\u5728\u4f4d\u7f6e\u304b\u3089\u30b9\u30dd\u30c3\u30c8\u691c\u7d22\u7b49)<\/p>\n\n\n\n<p>\u30a4\u30d9\u30f3\u30c8\u306e\u767a\u751f\u983b\u5ea6\u3092\u8003\u3048\u308b\u3068\u3001Server Side\u7248\u3088\u308a\u3082WASM\u7248\u3067\u4f5c\u6210\u3057\u305f\u65b9\u304c\u826f\u3044\u3068\u601d\u308f\u308c\u308b\u3002(\u4fdd\u6301\u3067\u304d\u308b\u30c7\u30fc\u30bf\u306e\u4e0a\u9650\u304c\u6c17\u306b\u306a\u308b\u3068\u3053\u308d\u3060\u304c\u30fb\u30fb\u30fb)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>HTML5\u3092\u30b5\u30dd\u30fc\u30c8\u3057\u3066\u3044\u308b\u30d6\u30e9\u30a6\u30b6\u3067\u306f\u3001GPS\u7b49\u3092\u4f7f\u7528\u3057\u3066\u3001\u4f4d\u7f6e\u60c5\u5831\u3092\u5f97\u308b\u3001g &hellip; <a href=\"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=315\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,10,9,4],"tags":[],"class_list":["post-315","post","type-post","status-publish","format-standard","hentry","category-asp-net-core","category-blazor","category-c","category-4"],"_links":{"self":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/315","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=315"}],"version-history":[{"count":9,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/315\/revisions"}],"predecessor-version":[{"id":325,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/315\/revisions\/325"}],"wp:attachment":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}