実行結果' ; $html .= '

データを取得できませんでした…。

' ; } else { // 見出し $html .= '

リアルタイム地図

' ; // データがある場合のみ解析処理 if( isset($array[0]['segments']) && !empty($array[0]['segments']) ) { // ストーリーラインの配列を[昔→今]から[今→昔]に並び替え krsort( $array[0]['segments'] ) ; // 全てのトラックポイントを取得していく foreach( $array[0]['segments'] as $item ) { // 最終時刻の記録 if( isset($item['endTime']) && !empty($item['endTime']) ) { // 時刻を記録 $time = $item['endTime'] ; } // 最新のセグメントが[場所]の場合 if( $item['type'] == 'place') { // 自宅、会社、学校の場合はスキップ (有効設定の場合のみ) if( ( $item['place']['type'] == 'home' && $skip_home ) || ( $item['place']['type'] == 'work' && $skip_work ) || ( $item['place']['type'] == 'school' && $skip_school ) ) { continue ; } // 場所の緯度・経度を配列[$geo]に格納 $geo = array( $item['place']['location']['lat'] , $item['place']['location']['lon'] ) ; } // 最新のセグメントが[運動]の場合 elseif( $item['type'] == 'move' || $item['type'] == 'off' ) { // アクティビティの存在を確認 if( isset( $item['activities'][0] ) ) { // アクティビティの配列を[昔→今]から[今→昔]にする krsort( $item['activities'] ) ; // トラックポイントの解析 foreach( $item['activities'] as $activities ) { // トラックポイントの存在を確認 if( isset( $activities['trackPoints'][0]['lat']) && isset( $activities['trackPoints'][0]['lon']) ) { // トラックポイントの配列を[昔→今]から[今→昔]にする krsort( $activities['trackPoints'] ) ; // 解析 foreach( $activities['trackPoints'] as $trackpoints ) { // 最新の緯度・経度を配列[$geo]に格納 if( isset( $trackpoints['lat'] ) && isset( $trackpoints['lon'] ) ) { $geo = array( $trackpoints['lat'] , $trackpoints['lon'] ) ; break ; } } } // 最新の緯度・経度が取得できた時点でループ終了 if( isset( $geo ) ) { break ; } } } // 最新の緯度・経度が取得できた時点でループ終了 if( isset($geo) ) { break ; } } } } // 位置情報がない場合 if( !isset( $geo ) || empty( $geo ) || !isset( $time ) || empty( $time ) ) { $html .= '

今日はまだ、行動していないみたいです…。

' ; } // 位置情報がある場合 else { // 緯度・経度を利用して、Google Static Mapsで地図を表示 $html .= '

' . date( 'Y年n月j日のH時i分' , strtotime( $time ) ) . 'に、下記の位置にいました。

' ; $html .= '

' ; } } ?> Moves APIを利用したリアルタイム地図のサンプルデモ

配布元: Syncer