{"id":1336,"date":"2014-04-29T16:59:00","date_gmt":"2014-04-29T07:59:00","guid":{"rendered":"http:\/\/blog.sensuishi.net\/?p=1336"},"modified":"2014-05-02T03:46:55","modified_gmt":"2014-05-01T18:46:55","slug":"post-1336","status":"publish","type":"post","link":"https:\/\/blog.sensuishi.net\/?p=1336","title":{"rendered":"Geolocation API \u3067\u30b9\u30bf\u30c3\u30d5\u306e\u73fe\u5728\u5730\u3092\u628a\u63e1"},"content":{"rendered":"<p>\u696d\u52d9\u7528\u30b5\u30a4\u30c8\u306b\u30ed\u30b0\u30a4\u30f3\u3057\u305f\u969b\u3001\u643a\u5e2f\u306e\u4f4d\u7f6e\u60c5\u5831\u30b5\u30fc\u30d3\u30b9\u3092DB\u306b\u4fdd\u5b58\u3057\u3001\u8ecc\u8de1\u3092\u8fbf\u3063\u305f\u308a\u3001\u6700\u7d42\u66f4\u65b0\u5834\u6240\u3067\u306e\u4e00\u89a7\u3092\u30de\u30c3\u30d4\u30f3\u30b0\u3059\u308b\u3053\u3068\u3067\u3001\u73fe\u5834\u306b\u8fd1\u3044\u4eba\u9593\u3092\u8996\u899a\u7684\u306b\u63a2\u305b\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p><a href=\"http:\/\/blog.sensuishi.net\/wp-content\/uploads\/2014\/04\/maps.jpg\"><img loading=\"lazy\" src=\"http:\/\/blog.sensuishi.net\/wp-content\/uploads\/2014\/04\/maps-300x170.jpg\" alt=\"maps\" width=\"300\" height=\"170\" class=\"alignnone size-medium wp-image-1344\" srcset=\"https:\/\/blog.sensuishi.net\/wp-content\/uploads\/2014\/04\/maps-300x170.jpg 300w, https:\/\/blog.sensuishi.net\/wp-content\/uploads\/2014\/04\/maps-1024x583.jpg 1024w, https:\/\/blog.sensuishi.net\/wp-content\/uploads\/2014\/04\/maps.jpg 1246w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>javascript\u3067geolocation\u3092\u52d5\u304b\u3057\u73fe\u5728\u5730\u3092\u53d6\u5f97\u3001\u305d\u308c\u3092ajax\u3067DB\u306b\u683c\u7d0d\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u306bPOST\u3057\u3066\u3084\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u307e\u305a\u306f&lt;HEAD&gt;\u3068&lt;\/HEAD&gt;\u9593\u306b&lt;script src=&quot;http:\/\/code.jquery.com\/jquery-latest.min.js&quot;&gt;&lt;\/script&gt;\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p>\u7d9a\u3044\u3066&lt;BODY&gt;\u3068&lt;\/BODY&gt;\u9593\u306b\u4ee5\u4e0b\u306e\u5185\u5bb9\u3092\u8ffd\u52a0<\/p>\n<p>&lt;script type=&quot;text\/javascript&quot;&gt;<br \/>\n&lt;?PHP<br \/>\n$staffId=8;\/\/\u5916\u90e8\u8a00\u8a9e\u3067\u4f7f\u3063\u3066\u3044\u308bID\u7b49<br \/>\n?&gt;<br \/>\nfunction getStaffPosition(){<\/p>\n<p>&nbsp;&nbsp;navigator.geolocation.getCurrentPosition(successCallback, errorCallback);<br \/>\n&nbsp;&nbsp;<br \/>\n&nbsp;&nbsp;\/***** \u30b9\u30bf\u30c3\u30d5\u306e\u73fe\u5728\u306e\u4f4d\u7f6e\u60c5\u5831\u3092\u53d6\u5f97 *****\/<br \/>\n&nbsp;&nbsp;function successCallback(position) {<br \/>\n&nbsp;&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;var sid = &lt;?php echo $staffId;?&gt;;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;var lat = position.coords.latitude;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;var long = position.coords.longitude;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;var alt = position.coords.altitude;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;var timestamp = &lt;?PHP echo date(&#8216;YmdHis&#8217;); ?&gt;;\/*****iOS\u306b\u30ad\u30e3\u30c3\u30b7\u30e5\u3055\u305b\u306a\u3044\u5bfe\u7b56*****\/<\/p>\n<p>&nbsp;&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;$.ajax({<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type: &quot;POST&quot;,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;url: &quot;mail.php&quot;,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dataType: &apos;text&apos;,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data: {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sid: sid,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lat: lat,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;long: long,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alt: alt,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timestamp: timestamp<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}).done(function( msg ) {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert( &quot;Data Saved: &quot; + msg );<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;});<br \/>\n&nbsp;&nbsp;}<br \/>\n&nbsp;&nbsp;<br \/>\n&nbsp;&nbsp;\/***** \u4f4d\u7f6e\u60c5\u5831\u304c\u53d6\u5f97\u3067\u304d\u306a\u3044\u5834\u5408 *****\/<br \/>\n&nbsp;&nbsp;function errorCallback(error) {<br \/>\n&nbsp;&nbsp;  var err_msg = &quot;&quot;;<br \/>\n&nbsp;&nbsp;  switch(error.code)<br \/>\n&nbsp;&nbsp;  {<br \/>\n&nbsp;&nbsp;    case 1:<br \/>\n&nbsp;&nbsp;      err_msg = &quot;\u4f4d\u7f6e\u60c5\u5831\u306e\u5229\u7528\u304c\u8a31\u53ef\u3055\u308c\u3066\u3044\u307e\u305b\u3093&quot;;<br \/>\n&nbsp;&nbsp;      break;<br \/>\n&nbsp;&nbsp;    case 2:<br \/>\n&nbsp;&nbsp;      err_msg = &quot;\u30c7\u30d0\u30a4\u30b9\u306e\u4f4d\u7f6e\u304c\u5224\u5b9a\u3067\u304d\u307e\u305b\u3093&quot;;<br \/>\n&nbsp;&nbsp;      break;<br \/>\n&nbsp;&nbsp;    case 3:<br \/>\n&nbsp;&nbsp;      err_msg = &quot;\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u3057\u307e\u3057\u305f&quot;;<br \/>\n&nbsp;&nbsp;      break;<br \/>\n&nbsp;&nbsp;  }<br \/>\n&nbsp;&nbsp;  document.getElementById(&quot;show_result&quot;).innerHTML = err_msg;<br \/>\n&nbsp;&nbsp;  \/\/document.getElementById(&quot;show_result&quot;).innerHTML = error.message;\/\/\u30c7\u30d0\u30c3\u30b0\u7528<br \/>\n&nbsp;&nbsp;}<\/p>\n<p>}<\/p>\n<p>getStaffPosition();<\/p>\n<p>\u3053\u308c\u3060\u3051\u3067\u3059\u3002<br \/>\n$.ajax\u306e\u90e8\u5206\u304c\u9001\u4fe1\u3057\u3066\u3044\u308b\u30c7\u30fc\u30bf\u3067\u3059\u3002<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;$.ajax({<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type: &quot;POST&quot;,\/\/METHOD<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;url: &quot;mail.php&quot;,\/\/\u9001\u4fe1\u5148(\u540c\u4e00\u30b5\u30fc\u30d0\u30fc\u306b\u9650\u308b)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dataType: &apos;text&apos;,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data: {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sid: sid,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lat: lat,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;long: long,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alt: alt,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timestamp: timestamp<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<\/p>\n<p>\u307e\u305fajax\u3067\u9001\u53d7\u4fe1\u3067\u304d\u308c\u3070\u30dd\u30c3\u30d7\u30a2\u30c3\u30d7\u8868\u793a\u3057\u307e\u3059\u304c\u3001\u4ee5\u4e0b\u306e\u90e8\u5206\u3092\u524a\u9664\u3059\u308c\u3070\u305d\u308c\u3092\u6d88\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n.done(function( msg ) {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert( &quot;Data Saved: &quot; + msg );<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;})<\/p>\n<p>\u307e\u305fajax\u3067POST\u3055\u308c\u305f\u30c7\u30fc\u30bf\u3092\u53d7\u3051\u3066\u51e6\u7406\u3059\u308b\u30d5\u30a1\u30a4\u30ebmail.php\u306f\u3053\u3093\u306a\u611f\u3058\u3067\u3059\u3002<br \/>\n\u5b9f\u969b\u306b\u306fDB\u306bINSERT\u3059\u308b\u51e6\u7406\u3092\u5165\u308c\u3066\u3044\u307e\u3059\u3002<br \/>\n&lt;?php<br \/>\nmb_language(&apos;uni&apos;);<br \/>\nmb_internal_encoding(&apos;UTF-8&apos;);<\/p>\n<p>echo &apos;post data is &apos;.$_POST[&quot;lat&quot;].&quot;&#038;&quot;.$_POST[&quot;lng&quot;].&quot;&#038;&quot;.$_POST[&quot;sid&quot;].&quot;&#038;&quot;.$_POST[&quot;timestamp&quot;];<\/p>\n<p>$to = &apos;to@foo.com&apos;;         \/\/\u9001\u4fe1\u5148\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9<br \/>\n$subj = &apos;TEST&apos;;     \/\/\u4ef6\u540d<br \/>\n$from = &apos;From: from@hoge.com&apos;; \/\/\u9001\u4fe1\u5143\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9<\/p>\n<p>mb_send_mail($to, $subj, $_POST[&quot;lat&quot;].&quot;:&quot;.$_POST[&quot;long&quot;].&quot;:&quot;.$_POST[&quot;sid&quot;], $from); \/\/\u30e1\u30fc\u30eb\u9001\u4fe1<\/p>\n<p>?&gt;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u696d\u52d9\u7528\u30b5\u30a4\u30c8\u306b\u30ed\u30b0\u30a4\u30f3\u3057\u305f\u969b\u3001\u643a\u5e2f\u306e\u4f4d\u7f6e\u60c5\u5831\u30b5\u30fc\u30d3\u30b9\u3092DB\u306b\u4fdd\u5b58\u3057\u3001\u8ecc\u8de1\u3092\u8fbf\u3063\u305f\u308a\u3001\u6700\u7d42\u66f4\u65b0\u5834\u6240\u3067\u306e\u4e00\u89a7\u3092\u30de\u30c3\u30d4\u30f3\u30b0\u3059\u308b\u3053\u3068\u3067\u3001\u73fe\u5834\u306b\u8fd1\u3044\u4eba\u9593\u3092\u8996\u899a\u7684\u306b\u63a2\u305b\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002 javascript\u3067geolocation [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1344,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[69,18,65],"tags":[123,124],"_links":{"self":[{"href":"https:\/\/blog.sensuishi.net\/index.php?rest_route=\/wp\/v2\/posts\/1336"}],"collection":[{"href":"https:\/\/blog.sensuishi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.sensuishi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.sensuishi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.sensuishi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1336"}],"version-history":[{"count":10,"href":"https:\/\/blog.sensuishi.net\/index.php?rest_route=\/wp\/v2\/posts\/1336\/revisions"}],"predecessor-version":[{"id":1351,"href":"https:\/\/blog.sensuishi.net\/index.php?rest_route=\/wp\/v2\/posts\/1336\/revisions\/1351"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.sensuishi.net\/index.php?rest_route=\/wp\/v2\/media\/1344"}],"wp:attachment":[{"href":"https:\/\/blog.sensuishi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.sensuishi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1336"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.sensuishi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}