http://wordpressgogo.com/customize/static_maps_api.html

この中 デザインについても参考サイト集がある

 

 

今回はWordPressに限った話ではないが、地図をウェブサイト上に表示する一つの方法についてである。企業サイト・商用ホームページを作成していると、会社やお店の位置を表す地図を載せたい場面というのは結構あるはずだ。地図を載せる方法としては、イラストレーターなどで独自に描いた地図、Google Maps APIやYahoo Maps APIなどのAPIを利用した地図が一般的だろう。ここで紹介するのは、Google Mapsの地図を使った方法だが、APIを一切使わずに、<img>タグだけで自由に地図を張り付けることができる方法だ。

まずは次の地図を見てほしい。これは見慣れたGoogle Mapsだが、<img>タグで読み込んでおり、JavaScriptを一切使用していない。そのため、携帯電話でもGoogle Mapsの地図を表示できる。また静的に読み込むため、各種APIを使用してJavaScriptを使うよりも、表示されるまでの時間がかなり短いはずだ。

 

これは、Google Static Maps APIを使用して実現している。この<img>タグのコードを見てみよう。たった1行のコードでGoogle Mapsをサイト上に表示できてしまうのだ。静的に読み込んでいるので通常のGoogle Mapsのようにぐりぐり動かすことはできないので注意してほしい。
PLAIN TEXT
CODE:
<img src=”http://maps.google.com/staticmap?center=35.658517,139.701334&markers=35.658517,139.701334,redc&zoom=16&size=512×300&key=ABQIAAAAT–ITJplvWF-DcJffBzSbRSfMB8pWqvvd1FJvhYen9GdTdnNKxTEhHNPV0XPH4pg0Hidf6yKctNiLA” width=”512″ height=”300″ class=”imageframe” alt=”Google Static Mapsサンプル” />


さて、ここからどのようにしてこのGoogle Static Maps APIを使うか簡単に見てみよう。まずはじめに、Google Static Maps APIを利用するためには、Google Maps API Keyが必要になるので取得してほしい。サイトのURLを入力するだけで無料で取得できる。パラメータ
http://maps.google.com/staticmap?parameters
parametersの部分に位置情報やサイズ、マーカー情報を指定することになる。パラメータは&でつなぐ。使用できるパラメータは以下のとおり。
center
必須。中央の座標。緯度・経度を指定する。,(カンマ)で区切る。例:center=35.658517,139.701334
zoom
必須。ズームレベルを指定する。値は0~19の間。例:zoom=16
size
必須。地図のサイズを指定する。値はwidthxheightで、指定できる地図の最大の大きさは512×512である。例:size=512×300
maptype
オプション。地図の表示タイプを指定できる。値はroadmapとmobileの2種で、roadmapがデフォルト。roadmapは通常の地図で、mobileは携帯用に見やすくしたもの。例:maptype=roadmap
markers
オプション。マーカーを地図上に配置する。マーカーを指定すると、centerやzoomは指定しなくてもよい。緯度・経度・マーカーの色(red,blue,green)・マーカーの文字(a-z)を指定できる。複数のマーカーを指定するときは、|(パイプ、%7C )で区切る。例:markers=35.658517,139.701334,redc
key
必須。Google Maps API Keyで取得したキーを指定する。

座標の指定方法
このGoogle Static Maps APIで一番面倒なのが、緯度経度の座標を指定するところだろう。緯度経度の座標はGoogle マップやGeocoding.jpで見つけることができる。

Google マップの場合、Google マップで表示させたい地図の位置に中心座標を動かし、地図の右上にある、「このページのリンク」をクリックするとiframeでの埋め込み用のタグが出てくる。このタグの中に「ll=35.658517,139.701334」と指定してあるところがあるのでこの数字をそのままcenter、もしくはmarkersに張り付ける。Geocoding.jpでは住所を入力して地図を表示し、ポップアップの吹き出しに表示されている座標をコピペするといいだろう。

マーカーを表示する。
マーカーを地図上に表示するにはcenterと同様、緯度、経度を指定する。加えて、マーカーの色や文字を指定できる。下の地図はマーカーをとりあえずいっぱい並べてみたものだ。centerやzoomを指定しなければ、下のように複数マーカーを指定した場合、自動的に各マーカー間の中心座標に合わせて最適なサイズで地図を返してくれる。

 

制限事項
一日に読み込むことができるのは1000ユニーク画像という制限がある。Geocodingなどを使って動的に地図を読み込んだりすると、場合によってはこの制限に引っ掛かるのかもしれないが、一般的には問題ないと思う。

まとめ
さて、Google Static Maps APIを使用した、お手軽にGoogle Mapsの地図を張り付ける方法(携帯電話でも表示できる)を簡単にご紹介したが、Google Static Maps APIの詳しい説明は、マニュアルであるGoogle Static Maps API - Google Codeを参照してほしい。また、今回の内容は、Official Google Maps API Blogで知ったものだ。地図を作成する方法として、Static Map Wizardというものも紹介されている(IEでは動かないかも)。

静的にGoogle Mapsを使用できる利点は簡単に地図が作成できるということに加えて、JavaScriptが動かない環境、つまりは携帯電話でも表示できる点にあると思う。携帯電話で地図を表示しようと思うと、どうしても地図専用のサイトへのリンクを張るということが多かったと思うが、これで自分のサイト上に地図を載せることができるはずだ。

今回は特にWordPressに関係がない話だったが、WordPressでGoogle Maps APIを使用して地図を表示することができるプラグインもあるようだ。使用したことはないが、Lightweight Google Mapsなどのプラグインを使用すれば、ぐりぐり動かせる地図を簡単に作成することができるのではないだろうか。使用目的に応じて、地図を表示する手段を知っておくという意味で、今回のGoogle Static Maps APIは押さえておきたいところだ。

[追記] Google Static Maps APIの新機能が搭載されたので、Google Static Maps APIの機能が拡張(パスを表示可能に) で、拡張された機能をまとめてみたので参照してほしい。

Posted at 2008.02.22 1:44 pm | Category: カスタマイズ

  

 

  

 

This entry was posted on 月曜日, 5 月 26th, 2008 at 3:58 PM and is filed under 未分類. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

19 Responses to “グーグルマップについて”

party supplies Says:

Great blog! I definitely love how it is uncomplicated on my eyes as well as the information is well written. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your rss feed which need to do the trick! Have a nice day!

Annunaki Reptilian Agenda Says:

I typically don’t reply on web sites but you have some good readable material.

Rayford Inghram Says:

Happy I found your website not only was I bored as heck terrible cubicle, but I came across some awesome advice. It’s really a delight to be able to bookmark this one!

Hip Hop Says:

It’s shocking how many information and news come out on a weekly basis.

guitar lessons dvd Says:

It becomes clearly obvious that there is a lot to know about this. I think you have made a lot of fantastic points in your article.

sales consultant Says:

The quality of your article is very good. Nice reading, informative, and thought provoking.

backlinks Says:

Keep up the amazing work!! I love how you wrote this and I also like the colors here on this site. did you create this yourself or did you outsource it to a coder??

Click for Chiropractors Says:

I agree with a lot of what peoples comments are that I am reading here.

Website Rankings Says:

Thanks for some great thoughts there. I am kind of new to the internet , so I printed this off to put in my file, any better way to go about keeping track of it then printing?

HackingEdgecom Says:

Thanks very much for your distinct article;this is the kind of thing that keeps me awake through these day. I’ve been searching around for your site after asked to visit them from a buddy and was pleased when I was able to find it after searching for long time. Being a avid blogger, I’m glad to see others taking initivative and contributing to the community. I just wanted to comment to show my support for your blog as it’s very appleaing, and many bloggers do not get acknowledgment they deserve. I am sure I’ll visit again and will send some of my friends.

Young Jeezy Says:

I wasn’t aware of some of the information that you mentioned so I want to just say thank you.

made in china Says:

Hi,Your post rocks and is a good read! Thanks.

Gravura Says:

Thank you for the work you have put into your nice blog. We will bookmark to your blog because it is very informational. We love the site and will come back to see your new posts.

beatbox Says:

Excellent post.When talking about Palm Reading Diagram,it’s always interesting and mysterious.

Vancouver Escorts Says:

Hi,I read your blog every week,Now I have my own site too,LOL.

best skype interviewing tips Says:

I check your site every week,now I have my own site LOL!!!!!

Adrian Gilreath Says:

Hi there, I found your blog via Google while searching for first aid for a heart attack and your post looks very interesting for me.

Full Movie Downloads Says:

I can see you’re an expert at your field! I am launching a web site soon, and your details will probably be really intriguing for me.. Thanks for all your help and wishing you all the success.

best skype interviewing tips Says:

Hello , I just stopped in to visit your blog and thought I’d say I enjoyed myself .

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>