åãã£ãªã¢ãã¨ã«æºå¸¯ã®GPSãåå¾ããPHP
ãä»äºã§ä½¿ãã¨ãããã¨ããã£ã¦ãæºå¸¯ã§GPSãåå¾ãã¦å¦çããããã®PHPã¯ã©ã¹ãä½ãã¾ããã
PHPãªãPEARã§ããããããã®ãã®ã§ãããèªåç¨ã«ä½ãããã£ãã®ã§ä¸ããä½ããã¨ã«ãã¾ããã
åèã«ããã®ã¯ãã¡ã
http://www.phppro.jp/phptips/archives/vol40/2 http://www.yaskey.cside.tv/mapserver/note/gps.html http://www.plusmb.jp/2008/12/26/1934.html
ã¾ãã¯ãã£ãªã¢ãã¨ã«éãGPSæ©è½ã®ä½¿ãæ¹ãå
¨é¨åãã«ããã
ä»åã¯ï¼aï¼ã§ã®åå¾ã®ã¿ã§ããï¼inputï¼ã§ãã§ããããã§ãã
function GPS_output_link($url,$link_title){ //æºå¸¯GPSãªã³ã¯åå¾ï¼ãã£ãªã¢ãã¨ã®GPSåå¾ãªã³ã¯ãè¿ãã¾ããï¼ //å¼æ°ï¼ $url --- GPSãå¦çããã¹ã¯ãªããã®URLï¼æå®ããªã "" or 0 ã®å ´åã¯ç¾å¨è¡¨ç¤ºãã¦ãããã¼ã¸ã«è¨å®ï¼ //å¼æ°ï¼ $link_title --- ãªã³ã¯ã®ã¿ã¤ãã« if(!$url){$url = $_SERVER['PHP_SELF'];} $agent = $_SERVER["HTTP_USER_AGENT"]; if(preg_match("/^DoCoMo\/[12]\.0/i", $agent)){//DoCoMo echo "<a href=\"".$url."\" lcs>".$link_title."</a>"; } elseif(preg_match("/^(J\-PHONE|Vodafone|MOT\-[CV]980|SoftBank)\//i", $agent)){//SoftBank echo "<a href=\"location:auto?url=".$url."\">".$link_title."</a>"; } elseif(preg_match("/^KDDI\-/i", $agent) || preg_match("/UP\.Browser/i", $agent)){//au echo "<a href=\"device:gpsone?url=".$url."&ver=1&datum=0&unit=0\">".$link_title."</a>"; } elseif(preg_match("/^DDIPOCKET/i", $agent) || preg_match("/^WILLCOM/i", $agent)){//WILLCOM echo "<a href=\"http://location.request/dummy.cgi?my=".$url."&pos=$location\">".$link_title."</a>"; } else { echo $link_title ; } }
functionã§ãªã³ã¯å
ã®URLã¨ãªã³ã¯ã®ã¿ã¤ãã«ã渡ãã°ãããããã®ãã£ãªã¢ãã¨ã«å¤å¥ãã¦GPSåå¾ï¼aï¼ãåºåãã¦ããã¾ãã
ä¾ãã°ãHTMLã«ãï¼?php GPS_output_link(SITE_URL,"GPSä½ç½®åå¾"); ?ï¼ããªãã¦æ¸ãã°åºåãã¦ããã¾ãã
auã¯ãã©ã¡ã¼ã¿ã¼ã渡ãã¦ããããããªã«ã¿ãã§ãã©ã¡ã¼ã¿ã¼ãåãåããã¨ãã§ãã¾ããã詳ããã¯ãªã³ã¯å
ãè¦ã¦ãã ããã
class GPS_param_get{ //緯度 latitudeï¼dd.mm.ss.sssï¼ var $lat; //çµåº¦ longitudeï¼dd.mm.ss.sssï¼ var $lon; //緯度ï¼ä¸ç測å°ç³»ã«å¤æï¼00.000000ï¼ var $lat_world; //çµåº¦ï¼ä¸ç測å°ç³»ã«å¤æï¼00.000000ï¼ var $lon_world; //ã³ã³ã¹ãã©ã¯ã¿ function GPS_param_get(){ //æºå¸¯GPSã§åå¾ãããã©ã¡ã¼ã¿ã¼ãã緯度çµåº¦ãåå¾ //è¿ãå¤ $hoge['lat'] -> 緯度ã$hoge['lon'] -> çµåº¦ $agent = $_SERVER["HTTP_USER_AGENT"]; if(preg_match("/^DoCoMo\/[12]\.0/i", $agent)){//DoCoMo if($_GET['lat'] && $_GET['lon']){ $lat = preg_replace("/\-/","+-",$_GET['lat']); $lon = preg_replace("/\-/","+-",$_GET['lon']); $lat = preg_split("/\+/",$lat); $lon = preg_split("/\+/",$lon); $this->lat = $lat[1]; $this->lon = $lon[1]; //ä¸ç測å°ç³»ã«å¤æ $location_converted = $this->location_convert($lat[1],$lon[1]); $this->lat_world = $location_converted['lat_converted']; $this->lon_world = $location_converted['lon_converted']; }else{ return FALES; } } elseif(preg_match("/^(J\-PHONE|Vodafone|MOT\-[CV]980|SoftBank)\//i", $agent)){//SoftBank if($_GET['pos']){ $location = preg_replace("/N/","+",$_GET['pos']); $location = preg_replace("/E/","+",$location); $location = preg_replace("/S/","+-",$location); $location = preg_replace("/W/","+-",$location); $location = preg_split("/\+/",$location); $this->lat = $location[1]; $this->lon = $location[2]; //ä¸ç測å°ç³»ã«å¤æ $location_converted = $this->location_convert($location[1],$location[2]); $this->lat_world = $location_converted['lat_converted']; $this->lon_world = $location_converted['lon_converted']; }else{ return FALES; } } elseif(preg_match("/^KDDI\-/i", $agent) || preg_match("/UP\.Browser/i", $agent)){//au if($_GET['lat'] && $_GET['lon']){ $lat = preg_replace("/\-/","+-",$_GET['lat']); $lon = preg_replace("/\-/","+-",$_GET['lon']); $lat = preg_split("/\+/",$lat); $lon = preg_split("/\+/",$lon); $this->lat = $lat[1]; $this->lon = $lon[1]; //ä¸ç測å°ç³»ã«å¤æ $location_converted = $this->location_convert($lat[1],$lon[1]); $this->lat_world = $location_converted['lat_converted']; $this->lon_world = $location_converted['lon_converted']; }else{ return FALES; } } elseif(preg_match("/DDIPOCKET/i", $agent) || preg_match("/WILLCOM/i", $agent)){//WILLCOM if($_GET['pos']){ $location = preg_replace("/N/","+",$_GET['pos']); $location = preg_replace("/E/","+",$location); $location = preg_replace("/S/","+-",$location); $location = preg_replace("/W/","+-",$location); $location = preg_split("/\+/",$location); $this->lat = $location[1]; $this->lon = $location[2]; //ä¸ç測å°ç³»ã«å¤æ $location_converted = $this->location_convert($location[1],$location[2]); $this->lat_world = $location_converted['lat_converted']; $this->lon_world = $location_converted['lon_converted']; }else{ return FALES; } } else { ; } } function location_convert($lat,$lon){ //æºå¸¯GPSã§åå¾ãã緯度ã»çµåº¦æ å ±ã®æ¸å¼ãä¸ç測å°ç³»ã«å¤æãã //å¼æ°ï¼ $lat 緯度 //å¼æ°ï¼ $lon 軽度 //è¿ãå¤ $hoge['lat_converted'] -> å¤æããã緯度ã$hoge['lon_converted'] -> å¤æãããçµåº¦ $lat_convert = preg_split("/\./",$lat); if(preg_match("/^-[[:digit:]]+/",$lat_convert[0])){ $lat_converted = $lat_convert[0] - ( ($lat_convert[1]/ 60) + (( $lat_convert[2] + ($lat_convert[3] / 1000)) / 3600 ) ); }else{ $lat_converted = $lat_convert[0] + ( ($lat_convert[1]/ 60) + (( $lat_convert[2] + ($lat_convert[3] / 1000)) / 3600 ) ); } $lon_convert = preg_split("/\./",$lon); if(preg_match("/^-[[:digit:]]+/",$lon_convert[0])){ $lon_converted = $lon_convert[0] - ( ($lon_convert[1]/ 60) + (( $lon_convert[2] + ($lon_convert[3] / 1000)) / 3600 ) ); }else{ $lon_converted = $lon_convert[0] + ( ($lon_convert[1]/ 60) + (( $lon_convert[2] + ($lon_convert[3] / 1000)) / 3600 ) ); } return array("lat_converted"=>$lat_converted,"lon_converted"=>$lon_converted); } }//class GPS_param_get END
ããã¦ããã©ã¡ã¼ã¿ã¼ã®åãåãã¯ã©ã¹ã
åãã£ãªã¢ãã¨ã«ãã©ã¡ã¼ã¿ã¼ã®åºåãããããéãã®ã§ããã«åããã¦æååãæ´å½¢ãã¦ãã¾ãã
ã¡ã¤ã³ã¯GPS_param_get()ã§ãlocation_convert($lat,$lon)ã¯æ¸¬å°åº§æ¨ç³»ï¼dd.mm.ss.sssï¼ãä¸ç測å°ç³»ï¼dd.ddddddï¼ã«å¤æããé¢æ°ã§ãã
å¤ã®åãåºãã¯
$location = new GPS_param_get(); echo $location -> lat; echo $location -> lon_world;
ã¿ãããªæãã§åãåºãã¾ãã
ããç¨åº¦ããã¹ãã確èªããããªã£ã¦ããã®ã§ãããWILLCOMã ã確èªãã¦ããªãã®ã§åããªãããâ¦
GoogleMapStaticã¨çµã¿åãããã°ç°¡åãªãããã§ããã®ã§æ¥½ããã¼ã§ããã