root/lang/perl/HTTP-MobileAgent-Plugin-Location/trunk/lib/HTTP/MobileAgent/Plugin/Location/LocationObject.pm @ 19674

Revision 19674, 5.7 kB (checked in by kokogiko, 5 years ago)

Initial import

Line 
1package HTTP::MobileAgent::Plugin::Location::LocationObject;
2
3use warnings;
4use strict;
5use Carp;
6
7use version; our $VERSION = qv('0.0.1');
8use base qw/Class::Data::Inheritable Class::Accessor::Fast/;
9
10__PACKAGE__->mk_accessors(qw/accuracy mode/);
11
12sub __create_coord{
13    my $class = shift;
14
15    if (HTTP::MobileAgent->_use_geocoordinate) {
16        require HTTP::MobileAgent::Plugin::Location::LocationObject::GCC;
17        $class = "HTTP::MobileAgent::Plugin::Location::LocationObject::GCC";
18    } else {
19        require HTTP::MobileAgent::Plugin::Location::LocationObject::LG;
20        $class = "HTTP::MobileAgent::Plugin::Location::LocationObject::LG";
21    }
22
23    $class->create_coord(@_);
24}
25
26sub mesh7{
27    my $self = shift;
28
29    my ($lat,$lon);
30
31    if (HTTP::MobileAgent->_use_geocoordinate) {
32        my $point = $self->convert( degree => 'tokyo' );
33        ($lat,$lon) = map { int ($_ * 3600000) } ($point->lat,$point->lng);
34    } else {
35        ($lat,$lon) = map { int ($_ * 1000) } $self->datum_tokyo->format_second->array;
36    }
37
38    my @mesh = ();
39    my $ab = int($lat / 2400000);
40    my $cd = int($lon / 3600000) - 100;
41    my $x1 = ($cd +100) * 3600000;
42    my $y1 = $ab * 2400000;
43    my $e = int(($lat - $y1) / 300000);
44    my $f = int(($lon - $x1) / 450000);
45    $mesh[0] = $ab.$cd.$e.$f;
46    my $x2 = $x1 + $f * 450000;
47    my $y2 = $y1 + $e * 300000;
48    my $l3 = int(($lon - $x2) / 225000);
49    my $m3 = int(($lat - $y2) / 150000);
50    my $g = $l3 + $m3 * 2;
51    $mesh[1] = $mesh[0].$g; 
52    my $x3 = $x2 + $l3 * 225000;
53    my $y3 = $y2 + $m3 * 150000;
54    my $l4 = int(($lon - $x3) / 112500);
55    my $m4 = int(($lat - $y3) / 75000);
56    my $h = $l4 + $m4 * 2;
57    $mesh[2] = $mesh[1].$h; 
58    my $x4 = $x3 + $l4 * 112500;
59    my $y4 = $y3 + $m4 * 75000;
60    my $l5 = int(($lon - $x4) / 56250);
61    my $m5 = int(($lat - $y4) / 37500);
62    my $i = $l5 + $m5 * 2;
63    $mesh[3] = $mesh[2].$i; 
64    my $x5 = $x4 + $l5 * 56250;
65    my $y5 = $y4 + $m5 * 37500;
66    my $l6 = int(($lon - $x5) / 28125);
67    my $m6 = int(($lat - $y5) / 18750);
68    my $j = $l6 + $m6 * 2;
69    $mesh[4] = $mesh[3].$j;
70    my $x6 = $x5 + $l6 * 28125;
71    my $y6 = $y5 + $m6 * 18750;
72    my $l7 = int(($lon - $x6) / 14062.5);
73    my $m7 = int(($lat - $y6) / 9375);
74    my $k = $l7 + $m7 * 2;
75    $mesh[5] = $mesh[4].$k;
76
77    return $mesh[5];
78}
79
80
811;
82
83=head1 NAME
84
85HTTP::MobileAgent::Plugin::Location::LocationObject - Object for handling location object
86
87
88=head1 VERSION
89
90This document describes HTTP::MobileAgent::Plugin::Location::LocationObject version 0.0.1
91
92
93=head1 SYNOPSIS
94
95  use HTTP::MobileAgent::Plugin::Location;
96 
97  my $ma = HTTP::MobileAgent->new;
98  $ma->parse_location;
99  my $loc = $ma->location;
100 
101  # If $loc is not undef, it is L<HTTP::MobileAgent::Plugin::Location::LocationObject> object.
102  # More detail information of above sequence, see L<HTTP::MobileAgent::Plugin::Location>.
103 
104  # This class is subclass of L<Location::GeoTool> on default, or subclass of
105  # L<Geo::Coordinates::Converter> on optional.
106  # So see L<Location::GeoTool> or L<Geo::Coordinates::Converter> to know basic methods and properties.
107
108  if ($loc->mode eq "gps") { ... }
109 
110  # Get location requested mode by B<mode> method.
111  # It returns "gps" or "sector".
112
113  if ($loc->accuracy eq "gps") { ... }
114 
115  # Get Accuracy of returned location by B<accuracy> method.
116  # It returns "gps", "hybrid" or "sector".
117  # Real accuracy value is different by carrears and generations, but almost like below:
118  #   gps:      0m -  50m
119  #   hybrid:  50m - 300m
120  #   sector: 300m -
121
122  my $mesh7 = $loc->mesh7;
123 
124  # Get 7th mesh code of i-Area specification.
125  # See more detail on L<http://www.nttdocomo.co.jp/service/imode/make/content/iarea/>.
126
127
128=head1 NOTE
129
130Value of B<mode> and B<accuracy> is sometimes not same.
131Even if User want to get gps level accuracy data, but terminal cannot access gps satellite,
132it fallback to hyblid or sector level accuracy.
133
134
135=head1 DEPENDENCIES
136
137=over
138
139=item L<Class::Data::Inheritable>
140
141=item L<Class::Accessor::Fast>
142
143=item L<HTTP::MobileAgent::Plugin::Location::LocationObject::GCC>
144
145=item L<HTTP::MobileAgent::Plugin::Location::LocationObject::LG>
146
147=back
148
149
150=head1 BUGS AND LIMITATIONS
151
152No bugs have been reported.
153
154Please report any bugs or feature requests to C<nene@kokogiko.net>.
155
156
157=head1 AUTHOR
158
159OHTSUKA Ko-hei  C<< <nene@kokogiko.net> >>
160
161
162=head1 LICENCE AND COPYRIGHT
163
164Copyright (c) 2007, OHTSUKA Ko-hei C<< <nene@kokogiko.net> >>. All rights reserved.
165
166This module is free software; you can redistribute it and/or
167modify it under the same terms as Perl itself. See L<perlartistic>.
168
169
170=head1 DISCLAIMER OF WARRANTY
171
172BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
173FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
174OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
175PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
176EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
177WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
178ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
179YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
180NECESSARY SERVICING, REPAIR, OR CORRECTION.
181
182IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
183WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
184REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
185LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
186OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
187THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
188RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
189FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
190SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
191SUCH DAMAGES.
Note: See TracBrowser for help on using the browser.