blog/content/post/2009-06-28-00001184.md

206 lines
9.9 KiB
Markdown
Raw Normal View History

2019-03-31 11:00:21 +00:00
---
title: WebService::SimpleでGoogleMapsのHTTPジオコーディングをリクエスト
author: kazu634
date: 2009-06-28
url: /2009/06/28/_1281/
wordtwit_post_info:
- 'O:8:"stdClass":13:{s:6:"manual";b:0;s:11:"tweet_times";i:1;s:5:"delay";i:0;s:7:"enabled";i:1;s:10:"separation";s:2:"60";s:7:"version";s:3:"3.7";s:14:"tweet_template";b:0;s:6:"status";i:2;s:6:"result";a:0:{}s:13:"tweet_counter";i:2;s:13:"tweet_log_ids";a:1:{i:0;i:4679;}s:9:"hash_tags";a:0:{}s:8:"accounts";a:1:{i:0;s:7:"kazu634";}}'
categories:
- Perl
---
<div class="section">
<p>
<a href="http://yusukebe.com/" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://yusukebe.com/', 'ゆーすけべー');" target="_blank">ゆーすけべー</a>さんが作成しているWebService::SimpleでGoogleMapsのHTTPジオコーディングをリクエストしてみた。
</p>
<h4>
作成してみたコード
</h4>
<pre class="syntax-highlight">
<span class="synComment"># === Libraries ===</span>
<span class="synStatement">use strict</span>;
<span class="synStatement">use warnings</span>;
<span class="synStatement">use </span>YAML;
<span class="synStatement">use </span>WebService::Simple;
<span class="synComment"># === Main part ===</span>
<span class="synStatement">my</span> <span class="synIdentifier">$geocode</span> = WebService::Simple-&#62;<span class="synStatement">new</span>(
<span class="synConstant">base_url </span>=&#62; <span class="synConstant">&#34;http://maps.google.com/maps/geo&#34;</span>,
<span class="synConstant">param </span>=&#62; {
<span class="synConstant">output </span>=&#62; <span class="synConstant">'xml'</span>,
<span class="synConstant">hl </span>=&#62; <span class="synConstant">'ja'</span>,
<span class="synConstant">ie </span>=&#62; <span class="synConstant">'UTF8'</span>,
<span class="synConstant">oe </span>=&#62; <span class="synConstant">'UTF8'</span>,
}
);
<span class="synStatement">my</span> <span class="synIdentifier">$response</span> = <span class="synIdentifier">$geocode</span>-&#62;get( { <span class="synConstant">q </span>=&#62; <span class="synConstant">'仙台'</span>, } );
<span class="synStatement">print</span> <span class="synIdentifier">Dump</span> <span class="synIdentifier">$response</span>-&#62;parse_response();
</pre>
<h4>
実行結果
</h4>
<pre class="syntax-highlight">
~/working/tmp_perl/projects/scrape/starbucks on simoom634 <span class="synStatement">[</span><span class="synConstant">558</span><span class="synStatement">]</span> $: perl geocoding.pl
Wide character <span class="synError">in</span> <span class="synStatement">print</span> at geocoding.pl line <span class="synConstant">24</span>.
---
Response:
Placemark:
p1:
AddressDetails:
Accuracy: <span class="synConstant">9</span>
Country:
AddressLine: 仙台駅(宮城)
CountryName: 日本
CountryNameCode: JP
xmlns: urn:oasis:names:tc:ciq:xsdschema:xAL:<span class="synConstant">2</span>.<span class="synConstant"></span>
ExtendedData:
LatLonBox:
east: <span class="synConstant">140</span>.<span class="synConstant">8851966</span>
north: <span class="synConstant">38</span>.<span class="synConstant">2634446</span>
south: <span class="synConstant">38</span>.<span class="synConstant">2571494</span>
west: <span class="synConstant">140</span>.<span class="synConstant">8789014</span>
Point:
coordinates: <span class="synStatement">'</span><span class="synConstant">140.8820490,38.2602970,0</span><span class="synStatement">'</span>
address: 日本仙台駅(宮城)
p2:
AddressDetails:
Accuracy: <span class="synConstant">4</span>
Country:
AdministrativeArea:
AddressLine: 仙台
AdministrativeAreaName: 宮城県
CountryName: 日本
CountryNameCode: JP
xmlns: urn:oasis:names:tc:ciq:xsdschema:xAL:<span class="synConstant">2</span>.<span class="synConstant"></span>
ExtendedData:
LatLonBox:
east: <span class="synConstant">140</span>.<span class="synConstant">8945506</span>
north: <span class="synConstant">38</span>.<span class="synConstant">2573096</span>
south: <span class="synConstant">38</span>.<span class="synConstant">2510144</span>
west: <span class="synConstant">140</span>.<span class="synConstant">8882554</span>
Point:
coordinates: <span class="synStatement">'</span><span class="synConstant">140.8914030,38.2541620,0</span><span class="synStatement">'</span>
address: <span class="synStatement">'</span><span class="synSpecial">日本宮城県</span><span class="synConstant">, </span><span class="synSpecial">仙台</span><span class="synStatement">'</span>
p3:
AddressDetails:
Accuracy: <span class="synConstant">4</span>
Country:
AdministrativeArea:
AddressLine: 仙台
AdministrativeAreaName: 鹿児島県
CountryName: 日本
CountryNameCode: JP
xmlns: urn:oasis:names:tc:ciq:xsdschema:xAL:<span class="synConstant">2</span>.<span class="synConstant"></span>
ExtendedData:
LatLonBox:
east: <span class="synConstant">130</span>.<span class="synConstant">3027536</span>
north: <span class="synConstant">31</span>.<span class="synConstant">8113086</span>
south: <span class="synConstant">31</span>.<span class="synConstant">8050134</span>
west: <span class="synConstant">130</span>.<span class="synConstant">2964584</span>
Point:
coordinates: <span class="synStatement">'</span><span class="synConstant">130.2996060,31.8081610,0</span><span class="synStatement">'</span>
address: <span class="synStatement">'</span><span class="synSpecial">日本鹿児島県</span><span class="synConstant">, </span><span class="synSpecial">仙台</span><span class="synStatement">'</span>
p4:
AddressDetails:
Accuracy: <span class="synConstant">9</span>
Country:
AddressLine: 仙台(宮城)(地下鉄)
CountryName: 日本
CountryNameCode: JP
xmlns: urn:oasis:names:tc:ciq:xsdschema:xAL:<span class="synConstant">2</span>.<span class="synConstant"></span>
ExtendedData:
LatLonBox:
east: <span class="synConstant">140</span>.<span class="synConstant">8830496</span>
north: <span class="synConstant">38</span>.<span class="synConstant">2627856</span>
south: <span class="synConstant">38</span>.<span class="synConstant">2564904</span>
west: <span class="synConstant">140</span>.<span class="synConstant">8767544</span>
Point:
coordinates: <span class="synStatement">'</span><span class="synConstant">140.8799020,38.2596380,0</span><span class="synStatement">'</span>
address: 日本仙台(宮城)(地下鉄)
p5:
AddressDetails:
Accuracy: <span class="synConstant">4</span>
Country:
AdministrativeArea:
AdministrativeAreaName: 河南省
Locality:
DependentLocality:
AddressLine: 仙台<span class="synComment">&#38;#38215;</span>
DependentLocalityName: 叶<span class="synComment">&#38;#21439;</span>
LocalityName: 平頂山市
CountryName: 中華人民共和国
CountryNameCode: CN
xmlns: urn:oasis:names:tc:ciq:xsdschema:xAL:<span class="synConstant">2</span>.<span class="synConstant"></span>
ExtendedData:
LatLonBox:
east: <span class="synConstant">113</span>.<span class="synConstant">4589689</span>
north: <span class="synConstant">33</span>.<span class="synConstant">5313692</span>
south: <span class="synConstant">33</span>.<span class="synConstant">5250740</span>
west: <span class="synConstant">113</span>.<span class="synConstant">4526737</span>
Point:
coordinates: <span class="synStatement">'</span><span class="synConstant">113.4558213,33.5282216,0</span><span class="synStatement">'</span>
address: 中華人民共和国河南省平頂山市叶<span class="synComment">&#38;#21439;仙台&#38;#38215;</span>
p6:
AddressDetails:
Accuracy: <span class="synConstant">9</span>
Country:
AdministrativeArea:
AdministrativeAreaName: 北京
DependentLocality:
AddressLine: 仙台
DependentLocalityName: <span class="synComment">&#38;#24576;柔区</span>
CountryName: 中華人民共和国
CountryNameCode: CN
xmlns: urn:oasis:names:tc:ciq:xsdschema:xAL:<span class="synConstant">2</span>.<span class="synConstant"></span>
ExtendedData:
LatLonBox:
east: <span class="synConstant">116</span>.<span class="synConstant">6846597</span>
north: <span class="synConstant">40</span>.<span class="synConstant">2848593</span>
south: <span class="synConstant">40</span>.<span class="synConstant">2785641</span>
west: <span class="synConstant">116</span>.<span class="synConstant">6783645</span>
Point:
coordinates: <span class="synStatement">'</span><span class="synConstant">116.6815121,40.2817117,0</span><span class="synStatement">'</span>
address: 中華人民共和国北京<span class="synComment">&#38;#24576;柔区仙台</span>
p7:
AddressDetails:
Accuracy: <span class="synConstant">9</span>
Country:
AdministrativeArea:
AdministrativeAreaName: 山西省
Locality:
DependentLocality:
AddressLine: 仙台
DependentLocalityName: 介休市
LocalityName: 晋中市
CountryName: 中華人民共和国
CountryNameCode: CN
xmlns: urn:oasis:names:tc:ciq:xsdschema:xAL:<span class="synConstant">2</span>.<span class="synConstant"></span>
ExtendedData:
LatLonBox:
east: <span class="synConstant">112</span>.<span class="synConstant">1005663</span>
north: <span class="synConstant">37</span>.<span class="synConstant">1093635</span>
south: <span class="synConstant">37</span>.<span class="synConstant">1030683</span>
west: <span class="synConstant">112</span>.<span class="synConstant">0942711</span>
Point:
coordinates: <span class="synStatement">'</span><span class="synConstant">112.0974187,37.1062159,0</span><span class="synStatement">'</span>
address: 中華人民共和国山西省晋中市介休市仙台
Status:
code: <span class="synConstant">200</span>
request: geocode
name: 仙台
xmlns: http://earth.google.com/kml/<span class="synConstant">2</span>.<span class="synConstant"></span>
</pre>
<h4>
参考にしたサイト:
</h4>
<ul>
<li>
<a href="http://d.hatena.ne.jp/khashi/20090217/1234860159" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/khashi/20090217/1234860159', 'HTTP要求経由のジオコーディング &#8211; Scrapcode@はてなダイアリー');" target="_blank">HTTP要求経由のジオコーディング &#8211; Scrapcode@はてなダイアリー</a>
</li>
</ul>
</div>