This repository was archived by the owner on Feb 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.location.php
executable file
·1224 lines (1055 loc) · 32.9 KB
/
class.location.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
define('__I_AREA_DIR__', '/root/path/to/iarea');
/*
* [memo]
* Longitude 経度 本初子午線を中心に0~180度まである。本初子午線から東を東経(+)、西側を西経(-)とする。
* Latitude 緯度 赤道が0度、南北にそれぞれ90度まで
*/
/**
* Location Class
*
* @package my
* @version 1.0.0
* @access public
* @author anon <anon@anoncom.net>
* @copyright anon (anoncom.net)
* @since Fri.16, Mar. 2007
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @link http://labs.anoncom.net/
* @link http://blog.anoncom.net/
*/
class Location{
const NETWORK_PROVIDER_DOCOMO = 1;
const NETWORK_PROVIDER_KDDI = 2;
const NETWORK_PROVIDER_SOFTBANK = 3;
const NETWORK_PROVIDER_OTHER = 9;
const VERSION = '1.0.0';
/**
* 測地方法:簡易位置情報(基地局情報)
*
* @var int
*/
const GEODETIC_SIMPLE = 1;
/**
* 測地方法:アシストGPS
*
* @var int
*/
const GEODETIC_AGPS = 2;
const TOKYO = 'tokyo';
const WGA84 = 'wgs84';
/**
* point (format: degree, data: wgs84)
*
* @var array(double, double)
*/
private $point = array();
private $accuracy = null;
private $geometory = null;
/**
* constructor
*
*/
function __construct(){}
/**
* get Provider
* 接続元プロバイダ判別
*
* @access public
* @param void
* @return string
*/
public static function getProvider($host = null){
if($host == NULL || strlen($host)){
$host= $_SERVER['REMOTE_ADDR'];
}
// IPv4 であった場合
if(preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/", $host)){
$host = gethostbyaddr($host); // IPの場合はget Host By Addrする
}
if(self::endsWith($host, '.docomo.ne.jp')){
return self::NETWORK_PROVIDER_DOCOMO;
}elseif(self::endsWith($host, '.ezweb.ne.jp')){
return self::NETWORK_PROVIDER_KDDI;
}elseif(self::endsWith($host, '.jp-c.ne.jp')){
return self::NETWORK_PROVIDER_SOFTBANK;
}elseif(self::endsWith($host, '.jp-t.ne.jp')){
return self::NETWORK_PROVIDER_SOFTBANK;
}elseif(self::endsWith($host, '.jp-k.ne.jp')){
return self::NETWORK_PROVIDER_SOFTBANK;
}elseif(self::endsWith($host, '.jp-q.ne.jp')){
return self::NETWORK_PROVIDER_SOFTBANK;
}else{
return self::NETWORK_PROVIDER_OTHER;
}
}
/**
* Get Model Name Function
* 端末名を取得
*
* @param string | void
* @return string
* @access public
* @author anon
*/
public function getModelName($ua = NULL){
if(empty($ua)){ $ua = $_SERVER['HTTP_USER_AGENT']; }
// DoCoMo
if(self::startsWith($ua, 'DoCoMo/1.0')){
// get model name
$tmp = explode('/', $ua);
if(count($tmp) < 2){
return null;
}
return $tmp[2];
}elseif(self::startsWith($ua, 'DoCoMo/2.')){
if(self::startsWith($ua, 'DoCoMo/2.0 MST_v_SH2101V')){
return 'SH2101V';
}
// get model name
$tmp_ary = explode('/', $ua);
if(count($tmp) < 1){
return null;
}
$tmp = $tmp[1];
$tmp_str = str_replace('2.0 ', '', $tmp);
$tmp_num = strpos($tmp_str, '(', 1) ? strpos($tmp_str, '(', 1) + 1 : 0;
$tmp_str = substr($tmp_str, 0, $tmp_num - 1);
return $tmp_str;
}elseif(self::startsWit($ua, 'UP.Browser/')){
// old type model
$tmp = explode('/', $ua);
if(count($tmp) < 2){
return null;
}
$tmp_str = $tmp[1];
$tmp_num = (strpos(1, $tmp_str, '-', 1) ? strpos(1, $tmp_str, '-', 1) + 1 : 0);
$tmp_str1 = substr($tmp_str, 0, $tmp_num);
$tmp_str = str_replace($tmp_str1, '', $tmp_str);
$tmp_str = str_replace(' UP.Link', '', $tmp_str);
return $tmp_str;
}elseif(self::startsWith($ua, 'KDDI-')){
//au EZweb WAP2.0
$tmp = explode('/', $ua);
if(count($tmp) < 1){
return null;
}
$tmp_str = $tmp[0];
$tmp_str = str_replace('KDDI-', '', $tmp_str);
$tmp_str = str_replace(' UP.Browser', '', $tmp_str);
return $tmp_str;
}else{
if(
self::startsWith($ua, 'J-PHONE/')
|| self::startsWith($ua, 'Vodafone/')
|| self::startsWith($ua, 'SoftBank/')
|| self::startsWith($ua, 'MOT-')
){
// SoftBank
if(
isset($_SERVER['HTTP_X_JPHONE_MSNAME']) === FALSE
&& strlen($_SERVER['HTTP_X_JPHONE_MSNAME']) == 0){
return null;
}
return $_SERVER['HTTP_X_JPHONE_MSNAME'];
}
}
// other UserAgents
return 'Pc';
}
/**
* get Model Type
* キャリアごとの端末の種類(ただし判別はあくまでも位置情報の取得用)
*
* @access public
* @param void
* @return string / null
* @author anon <anon@anoncom.net>
*/
public function getModelType(){
$ua = $_SERVER['HTTP_USER_AGENT'];
switch(self::getProvider()){
case self::NETWORK_PROVIDER_DOCOMO: // DoCoMo
if(self::startsWith($ua, 'DoCoMo/1.0/')){
// mova
if($this->getModelName() == 'F505iGPS' || $this->getModelName() == 'F661i'){
return self::GEODETIC_SIMPLE;
}
return self::GEODETIC_AGPS;
}elseif(self::startsWith($ua, 'DoCoMo/2.')){
// FOMA
$gps = $this->getArrayMap('docomo.gps.devicelist.txt');
$max = count($gps);
for($i = 0; $i < $max; $i++){
if($this->getModelName() === $gps[$i]){
return self::GEODETIC_AGPS;
}
}
return self::GEODETIC_SIMPLE;
}
return null;
case self::NETWORK_PROVIDER_KDDI: // AU
if(
isset($_SERVER['HTTP_X_UP_DEVCAP_MULTIMEDIA']) === TRUE
&& preg_match('/^[0-9A-F](\d)/', $_SERVER['HTTP_X_UP_DEVCAP_MULTIMEDIA'], $tmp)
){
$ary = chunk_split($tmp[1], 1, ',');
$ary = explode(',', $ary);
if($ary[0] >= 2){
return self::GEODETIC_AGPS; // gpsOne
}
return self::GEODETIC_SIMPLE; // 簡易位置情報
}
return null;
case self::NETWORK_PROVIDER_SOFTBANK: // SoftBank
if(self::startsWith($ua, 'J\-PHONE/')){
$deny = array(
'J-N03S', 'J-SH05S', 'J-SH04BS', 'J-SH04S',
'J-PE03S', 'J-D03S', 'J-K03S', 'J-P03',
'J-T04', 'J-SH03', 'J-SA02', 'J-P02',
'J-DN02', 'J-SH02'
);
$max = count($deny);
for($i = 0; $i < $max; $i++){
if($this->getModelName() === $deny[$i]){
return null;
}
}
return self::GEODETIC_SIMPLE; // 2G
}elseif(
self::startsWith($ua, 'Vodafone')
|| self::startsWith($ua, 'SoftBank')
|| self::startsWith($ua, 'MOT-)')
){
$deny = array(
'V801SA','V801SH','V702MO','V702sMO','V702NK',
'V802N','VC701SI'
);
$max = count($deny);
for($i = 0; $i < $max; $i++){
if($this->getModelName() === $deny[$i]){
return null;
}
}
return self::GEODETIC_AGPS; // 3G
}
return null;
default:
return null;
}
}
/*
* get Array Map
* 外部マップファイルを読み込み、配列で返す
*
* @access private
* @param string
* @return array
* @author anon <anon@anoncom.net>
*/
function getArrayMap($filename){
if(file_exists($filename)){
$line = @file($filename, 1);
$max = count($line);
while($i < $max){
if(!preg_match('/^\s*#+.*/i', $line[$i])){ // コメント行無視
$map[] = rtrim($line[$i]); // 改行除去
}
$i++;
}
return $map;
}
return array(); // ERROR: null array
}
/**
* is location
* 位置情報が送出されているか
*
* @access public
* @param void
* @return boolean
* @author anon <anon@anoncom.net>
*/
function isLocation(){
switch($this->getVender()){
case self::NETWORK_PROVIDER_DOCOMO:
if(isset($_REQUEST['AREACODE'])){
return true;
}
if(isset($_REQUEST['lat']) && isset($_REQUEST['lon']) && isset($_REQUEST['geo'])){
return true;
}
break;
case self::NETWORK_PROVIDER_KDDI:
if(isset($_REQUEST['lat']) && isset($_REQUEST['lon']) && isset($_REQUEST['datum'])){
return true;
}
break;
case self::NETWORK_PROVIDER_SOFTBANK:
if(isset($_REQUEST['pos']) && isset($_REQUEST['geo'])){
return true;
}
break;
default:
if(isset($_REQUEST['lat']) && isset($_REQUEST['lon'])){
return true;
}
break;
}
return false;
}
/**
* get Location
* 位置情報を取得
*
* @access public
* @return array
* @author anon <anon@anoncom.net>
*/
function getLocation(){
switch($this->getVender()){
case self::NETWORK_PROVIDER_DOCOMO: $this->docomo(); break;
case self::NETWORK_PROVIDER_KDDI: $this->au(); break;
case self::NETWORK_PROVIDER_SOFTBANK: $this->softbank(); break;
default: $this->pc(); break;
}
return $this->point;
}
public function setPoint($latitude, $longitude = null){
if($longitude === NULL){
$point = $latitude; unset($latitude);
if($point instanceof Location_Point == TRUE){
$this->point = $point;
}elseif(is_array($point) == TRUE){
$this->point = new Location_Point($point);
}
}
$this->point = new Location_Point($latitude, $longitude);
}
private function setGeometory($geometory){ $this->geometory = $geo; }
private function setAccuracy($accuracy){ $this->accuracy = $acr; }
/**
* get Point
* 位置情報を配列で取得
*
* @access public
* @param void
* @return array
* @author anon <anon@anoncom.net>
*/
public function getPoint(){
return $this->point;
}
/**
* get Geometry
* 測地系を取得
*
* @access public
* @param void
* @return string
* @author anon <anon@anoncom.net>
*/
public function getGeometory(){
if($this->geometory == null){
$this->getLocation();
}
return $this->geometory;
}
/**
* <strong>get Accuracy</strong><br />
* 測定精度を取得
*
* @access public
* @param void
* @return string
* @author anon <anon@anoncom.net>
*/
public function getAccuracy(){
if($this->accuracy == null){
$this->getLocation();
}
return $this->accuracy;
}
/**
* DoCoMo
* DoCoMoからの位置情報を取得
*
* @access privarte
* @param void
* @return void
* @author anon <anon@anoncom.net>
*/
function docomo(){
if(!isset($_REQUEST['AREACODE']) && ((!isset($_GET['lat']) && !isset($_GET['lon'])) && !isset($_GET['pos']))){
$point = array(35.000000, 139.000000);
$geo = self::WGA84;
$acr = 1;
}else{
if((isset($_POST['LAT']) && !empty($_POST['LAT'])) && (isset($_POST['LON']) && !empty($_POST['LON'])) && (isset($_POST['XACC']) && !empty($_POST['XACC'])) && (isset($_POST['GEO']) && !empty($_POST['GEO']))){
// posinfo 処理
$latitude = ereg_replace('[+-]', '', $_POST['LAT']);
$longitude = ereg_replace('[+-]', '', $_POST['LON']);
$latitude = Location_Converter::convertDms2Degree($latitude);
$longitude = Location_Converter::convertDms2Degree($longitude);
$point = array($latitude, $longitude);
$geo = strtolower($_POST['GEO']); // wgs84
$acr = $_POST['XACC'];
}elseif(isset($_POST['AREACODE'])){
// Open i area処理
$point = $this->getFrom_iArea($_POST['AREACODE']);
$point[0] = Location_Converter::convertDms2Degree($point[0]);
$point[1] = Location_Converter::convertDms2Degree($point[1]);
$point = Location_Converter::convertTokyo2Wgs84($point);
//$geo = self::TOKYO;
$gep = self::WGA84;
$acr = 0;
}elseif(isset($_GET['pos'])){
// mova(GPS)処理
if(isset($_GET['pos'])){
// 測地系
$geo = $_GET['geo'];
if(preg_match('/^[NS][+\-]?([0-9]{2}\.[0-9]{2}\.[0-9]{2}\.[0-9]{2})[EW]\-?([0-9]{3}\.[0-9]{2}\.[0-9]{1,2}\.[0-9]{1,2})/', $_GET['pos'], $matches)){
$latitude = $matches[1]; // 北緯
$longitude = $matches[2]; // 東経
$point = array($latitude, $longitude);
$acr = $_GET['X-acc']; // 精度
}
}
}else{
// FOMA(GPS)処理
$latitude = ereg_replace('%2B', '', $_GET['lat']);
$longitude = ereg_replace('%2B', '', $_GET['lon']);
$point = array($latitude, $longitude);
$geo = $_GET['geo'];
$acr = $_GET['x-acc'];
}
}
$this->setPoint($point);
$this->setGeometory($geo);
$this->setAccuracy($acr);
}
/**
* <strong>au</strong><br />
* auからの位置情報を取得
*
* @access privarte
* @param void
* @return void
* @author anon <anon@anoncom.net>
*/
function au(){
if(!isset($_GET['lat']) && !isset($_GET['lon'])){
$point = array(35.000000, 139.000000);
$geo = self::WGA84;
$acr = 1;
}else{
if(empty($_GET['smaj']) && empty($_GET['smin']) && empty($_GET['vert'])){
// 簡易位置情報処理
$point = array($_GET['lat'], $_GET['lon']);
//$geo = $_GET['datum'];
$geo = self::WGA84;
$acr = 3; // 取れないので3にしておく
}else{
// gpsOne処理
$latitude = ereg_replace('%2B', '', $_GET['lat']);
$longitude = ereg_replace('%2B', '', $_GET['lon']);
$smaj = $_GET['smaj'];
//$geo = $_GET['datum'];
$geo = self::WGA84;
if ($smaj < 50){
$acr = 3;
}elseif($smaj < 300){
$acr = 2;
}else{
$acr = 1;
}
}
$latitude = Location_Converter::convertDms2Degree($latitude);
$longitude = Location_Converter::convertDms2Degree($longitude);
$point = array($latitude, $longitude);
}
$this->setPoint($point);
$this->setGeo($geo);
$this->setAcr($acr);
}
/**
* <strong>SoftBank</strong><br />
* ソフトバンク携帯からの位置情報を取得
*
* @access privarte
* @param void
* @return void
* @author anon <anon@anoncom.net>
*/
function softbank(){
if(!isset($_SERVER['HTTP_X_JPHONE_GEOCODE']) && !isset($_GET['pos'])){
$point = array(35.000000, 139.000000);
$acr = 1;
}
if(isset($_GET['pos'])){
// 測地系
$geo = $_GET['geo'];
if(preg_match('/^[NS][+\-]?([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,3})[EW][+-]?([0-9]{1,3}\.[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,3})/', $_GET['pos'], $matches)){
$latitude = $matches[1]; // 北緯
$longitude = $matches[2]; // 東経
$acr = $_GET['x-acr'];
$latitude = Location_Converter::convertDms2Degree($latitude);
$longitude = Location_Converter::convertDms2Degree($longitude);
$point = array($latitude, $longitude);
}
}else{
if($_SERVER['HTTP_X_JPHONE_GEOCODE'] == '0000000%1A0000000%1A%88%CA%92%75%8F%EE%95%F1%82%C8%82%B5'){
$geocode = '3500000%1A1390000%1A%88%CA%92%75%8F%EE%95%F1%82%C8%82%B5';
}
list($latitude, $longitude, $address) = split('\%1A', $geocode);
// 緯度の整形
$latitude = substr($latitude, 0, 2).'.'.
substr($latitude, 2, 2).'.'.
substr($latitude, 4, 2);
// 経度の整形
$longitude = substr($longitude, 0, 3).'.'.
substr($longitude, 3, 2).'.'.
substr($longitude, 5, 2);
// 住所のデコード
$address = urldecode($address);
// 誤差精度
//$accuracy = 0;
$acr = 1;
// 測地系
$geo = self::TOKYO;
$point = array($latitude, $longitude);
$point = Location_Converter::convertDms2Degree($point);
$point = Location_Converter::convertTokyo2Wgs84($point);
}
$this->setPoint($point);
$this->setGeometory($geo);
$this->setAccuracy($acr);
}
/**
* <strong>Pc</strong><br />
* PCでの位置情報を取得
*
* @access privarte
* @param void
* @return void
* @author anon <anon@anoncom.net>
*/
function pc(){
if(isset($_GET['pos'])){
preg_match('/^[NS][+\-]?([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})[EW][+\-]?([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})/', $_GET['pos'], $matches);
$latitude = $matches[1]; // 北緯
$longitude = $matches[2]; // 東経
}else{
if(isset($_GET['lat'])){
$latitude = $_GET['lat'];
}
if(isset($_GET['lon'])){
$longitude = $_GET['lon'];
}
}
$geo = isset($_GET['geo']) ? $_GET['geo'] : self::WGA84;
$acr = isset($_GET['acr']) ? $_GET['acr'] : 2;
if(is_float($latitude) == FALSE){
$latitude = Location_Converter::convertDms2Degree($latitude);
}
if(is_float($longitude) == FALSE){
$longitude = Location_Converter::convertDms2Degree($longitude);
}
$point = array($latitude, $longitude);
$this->setPoint($point);
$this->setGeo($geo);
$this->setAcr($acr);
}
/**
* <strong>get from iArea</strong><br />
* DoCoMoのOpen i areaからdms形式の位置情報を取得
*
* @access privarte
* @param void
* @return array
* @author anon <anon@anoncom.net>
*/
function getFrom_iArea($areacode){
$area = file_get_contents(__I_AREA_DIR__ . '/iarea' . $areacode . '.txt');
/*
* iエリアでの位置情報の求め方
* iエリアでは、特定エリアの範囲をメッシュ方式で区切り、
* メッシュで区切ったうちのエリア範囲内の
* 最西端の経度
* 最南端の緯度
* 最東端の経度
* 最北北端の緯度
* の情報を持っている。今回はメッシュ情報を用いずに、
* この情報からエリアの中間地点を求め、
* そこの地点情報を返す仕様とする。
*/
$ary = explode(',', $area, 8);
$latitude = ($ary[6] + $ary[4]) / 7200000;
$longitude = ($ary[5] + $ary[3]) / 7200000;
//$latitude = Location_Converter::convertDegree2Dms($latitude);
//$longitude = Location_Converter::convertDegree2Dms($longitude);
return array($latitude, $longitude);
}
/**
* createLocationLink
* 各端末ごとにあわせた位置情報取得用HTMLリンクを出力する。
*
* @access public
* @param string url, string anchor_string
* @return string
* @author anon <anon@anoncom.net>
*/
function createLocationLink($uri, $str = 'getLocation'){
switch($this->getModelType()){
case 'igps':
$ret = '<a href="' . $uri . '" lcs>' . $str . '</a>'; break;
case 'iarea':
$uri = 'http://w1m.docomo.ne.jp/cp/iarea?ecode=OPENAREACODE&msn=OPENAREAKEY&posinfo=1&nl=' . urlencode($uri);
$ret = '<a href="' . $uri . '">' . $str . '</a>'; break;
case 'gpsone':
$uri = 'device:gpsone?url=' . urlencode($uri) . '&ver=1&datum=0&unit=0&acry=0&number=0';
$ret = '<a href="' . $uri . '">' . $str . '</a>'; break;
case 'location':
$uri = 'device:location?url=' . urlencode($uri);
$ret = '<a href="' . $uri . '">' . $str . '</a>'; break;
case '2g':
$ret = '<a href="' . $uri . '" z>' . $str . '</a>'; break;
case '3g':
$uri = 'location:auto?url=' . urlencode($url);
$ret = '<a href="' . $uri . '">' . $str . '</a>'; break;
default:
$ret = '<a href="' . $uri . '">' . $str . '</a>'; break;
}
return $ret;
}
/**
* Get Class Version Function
* バージョン情報を返す
*
* @param void
* @return string version
* @access public
*/
public function getVersion(){
return self::VERSION;
}
/**
*
*
* @param string $path
* @return bool
* @access private
*/
function _file_exists_ex($path, $use_include_path = true){
if($use_include_path == false){
return file_exists($path);
}
// check if absolute
if(preg_match('/^\//', $path)){
return file_exists($path);
}
$include_path_list = explode(PATH_SEPARATOR, get_include_path());
if(is_array($include_path_list) == false){
return file_exists($path);
}
foreach($include_path_list as $include_path){
if(file_exists($include_path . DIRECTORY_SEPARATOR . $path)){
return true;
}
}
return false;
}
/**
* 前方一致
* $haystackが$needleから始まるか判定します。
* @param string $haystack
* @param string $needle
* @return boolean
*/
private static function startsWith($haystack, $needle){
return strpos($haystack, $needle, 0) === 0;
}
/**
* 後方一致
* $haystackが$needleで終わるか判定します。
* @param string $haystack
* @param string $needle
* @return boolean
*/
private static function endsWith($haystack, $needle){
$length = (strlen($haystack) - strlen($needle));
// 文字列長が足りていない場合はFALSEを返します。
if($length <0) return FALSE;
return strpos($haystack, $needle, $length) !== FALSE;
}
/**
* 部分一致
* $haystackの中に$needleが含まれているか判定します。
* @param string $haystack
* @param string $needle
* @return boolean
*/
private static function matchesIn($haystack, $needle){
return strpos($haystack, $needle) !== FALSE;
}
}
/**
* 地点情報オブジェクト
* (内部地点情報は世界測地系(wgs84)のDegree形式で保存されます)
*/
class Location_Point{
private $point;
/**
* Constructor
*
* @param float|string $latitude Latitude
* @param float|string $longitude Longitude
*/
function __construct($latitude, $longitude = null){
if($longitude === NULL){
$point = $latitude; unset($latitude);
if($point instanceof self){
$this->point = $point->toArray();
return;
}elseif(Location_Converter::isValid($point, Location_Converter::FORMAT_LOCAPOINT)){
list($latitude, $longitude) = Location_Converter::decodeLocaPoint($point);
}
}
$this->point = array($latitude, $longitude);
}
public function toArray(){
return $this->point;
}
public function getLatitude(){
return $this->point[0];
}
public function getLongitude(){
return $this->point[1];
}
public function toDegree(){
return $this->toArray();
}
public function toDms(){
$latitude = Location_Converter::convertDegree2Dms($this->pont[0]);
$longitude = Location_Converter::convertDegree2Dms($this->point[1]);
return array($latitude, $longitude);
}
public function toTokyo(){
return Location_Converter::convertWgs842Tokyo($this->point);
}
public function toWgs84(){
return $this->toArray();
}
public function toLocaPoint(){
return array(Location_Converter::encodeLocaPoint($this->point[0], $this->point[1]));
}
}
class Location_Converter{
const FORMAT_DEGREE = 1;
const FORMAT_DMS = 2;
const FORMAT_LOCAPOINT = 4;
const __REGEX_PATTERN_DMS = '/^[+\-]?\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/';
const __REGEX_PATTERN_DEGREE = '/^[+\-]?\d{1,3}\.\d+$/';
const __REGEX_PATTERN_LOCAPOINT = '/^[A-Z]{2}\d\.[A-Z]{2}\d\.[A-Z]{2}\d\.[A-Z]{2}\d$/';
const WGS84 = 1;
const TOKYO = 2;
/**
* 入力された位置情報の形式の整合性をチェックします
*
* @param string|double $value
* @param in $flag
* @return bool
*/
public static function isValid($value, $flag){
switch($flag){
case self::FORMAT_DEGREE:
if(preg_match(self::__REGEX_PATTERN_DEGREE, strval($value)) == FALSE){
return false;
}
return is_float($value);
case self::FORMAT_DMS:
return preg_match(self::__REGEX_PATTERN_DMS, strval($value));
case self::FORMAT_LOCAPOINT:
return preg_match(self::__REGEX_PATTERN_LOCAPOINT, strval($value));
}
return false;
}
/**
* convert DMS to Degree
* DMS形式(dd.mm.ss.sss)の位置情報をDegree形式(dd.mmsss)に変換する
*
* @access public
* @param string $value
* @return float
* @author anon <anon@anoncom.net>
*/
public static function convertDms2Degree($value){
if(self::isValid($value, self::FORMAT_DMS) == FALSE){
return $value;
}
list($dd, $mm, $ss, $sss) = explode('.', $value);
// dms = ±dd.mm.ss.sss
// degree = dd + (mm / 60) + (ss / 3600) + (sss / 360000)
$ret = $dd + ($mm / 60) + ($ss / 3600) + ($sss / 360000);
$ret = sprintf('%0.6f', $ret);
return $ret;
}
/**
* convert Degree to DMS
* Degree形式(dd.mmsss)の位置情報をDMS形式(dd.mm.ss.sss)に変換する
*
* @access public
* @param float $value
* @return string
* @author PHPスクリプト無料配布所 :: PHP.TO
* @link http://php.to/tips/9/
*/
public static function convertDegree2Dms($value){
if(self::isValid($value, self::FORMAT_DEGREE) == FALSE){
return $value;
}
$d = floor($value);
$m = floor(($value - $d) * 60);
$s = floor(($value - $d - $m / 60) * 3600);
$u = floor(($value - $d - $m / 60 - $s / 3600) * 360000);
$ret = implode('.', array($d, $m, $s, $u));
return $ret;
}
/**
* convert to wgs84 from Tokyo
* 日本測地系の座標から世界測地系の座標に変換する
*
* @access public
* @param array $point
* @return array($latitude, $longitude)
* @author PHPスクリプト無料配布所 :: PHP.TO
* @link http://php.to/tips/9/
*/
public static function convertTokyo2Wgs84($point) {
$isDMS = false;
list($latitude, $longitude) = $point;
if(self::isValid($latitude, self::FORMAT_DMS)){
$latitude = self::convertDms2Degree($latitude);
$isDMS = true;
}
if(self::isValid($longitude, self::FORMAT_DMS)){
$longitude = self::convertDms2Degree($longitude);
$isDMS = true;
}
$point = array(
$latitude -
$latitude * 0.00010695
+ $longitude * 0.000017464
+ 0.0046017,
$longitude -
$latitude * 0.000046038
- $longitude * 0.000083043
+ 0.010040
);
if($isDMS == TRUE){
$point = self::convertDegree2Dms($point);
}
return $point;
}
/**
* convert to tokyo from wgs84
* 世界測地系から日本測地系の座標に変換します
*
* @access public
* @param array $point
* @return array
* @author anon <anon@anoncom.net>
*/
public static function convertWgs842Tokyo($point) {
$isDMS = false;