跳至主要内容

把Google Maps加到自己的Blog里"

具体效果可以看我主页的About me,这也算是Google Map最简单的玩法了,我就用dancemoon.net作例子,具体介绍一下在Blog添加Google Maps的方法。

首先需要到http://www.google.com/apis/maps/申请一个API key,你需要用你的GmailID登录。申请成功以后你会得到一个API key,和一段添加到网页的事例代码,去掉一些没有用的Html代码以后剩下:

<script src=" http://maps.google.com/maps?file=api&v=1&key= [API key]" type="text/javascript"></script>     <div id="map" style="width: 500px; height: 400px"></div>     <script type="text/javascript">     //<![CDATA[          var map = new GMap(document.getElementById("map"));     map.addControl(new GSmallMapControl());     map.centerAndZoom(new GPoint(-122.1419, 37.4419), 4);          //]]>     </script>


其中
<div id="map" style="width: 500px; height: 400px"></div>

这行可以自定义显示Google Maps的宽(width)和高(height)。

map.centerAndZoom(new GPoint(-122.1419, 37.4419), 4);

这行算是整段代码最重要的部分,可以用来调整Google Maps显示的地理位置(-122.1419, 37.4419)和大小(4)。我们下面要做的就是把这两行代码替换成适合自己的。

http://maps.google.com在地图上找到自己所在的位置,用鼠标双击,你双击的那点就会显示在地图的中央,然后点击右上角的Link to this page,地址栏里的地址就包含了你的坐标信息,比如我在的大连地址是:

http://maps.google.com/?ll=38.794768,121.294556&spn=1.051049,2.04071

其中38.794768,121.294556,就是大连的坐标,把他们替换到代码里:

map.centerAndZoom(new GPoint(121.294556, 38.794768), 15);

因为Google Maps显示的中国的信息有限,所以不要把最后的数值设得太小,我写的是15(最大到16),具体自己把握就行。

如果想在自己的位置上加个标记,那把下面这段代码加到map.centerAndZoom...这行下面:

map.addOverlay(new GMarker(new GPoint(121.294556, 38.794768)));

还想在标记上加上弹出气泡的功能,就加入下面一段:

    var dalian = new GMarker (new GPoint (121.294556, 38.794768));  GEvent.addListener (dalian, "click", function() {  dalian.openInfoWindowHtml ("我在大连 Oh!Yeah!");  });  map.addOverlay (dalian);

最后的代码就是这些:

<script src="http://maps.google.com/maps?file=api&v=1&key= [API key]" type="text/javascript"></script>     <div id="map" style="width: 400px; height: 300px"></div>     <script type="text/javascript">     //<![CDATA[          var map = new GMap(document.getElementById("map"));     map.addControl(new GSmallMapControl());     map.centerAndZoom(new GPoint(121.294556, 38.794768), 15);         var dalian = new GMarker (new GPoint (121.294556, 38.794768));  GEvent.addListener (dalian, "click", function() {  dalian.openInfoWindowHtml ("我在大连 Oh!Yeah!");  });  map.addOverlay (dalian);     //]]>     </script>

1/11/2006 6:19:25 AM Post by[dancemoon.net]

评论

此博客中的热门博文

How to Design a Store Front Sign

In this Article we will talk about designing a store front for a business. What color or size should your Letters & designs be? What to put on your sign and why?, then be ready to Get in touch with sign people and get your best deal. Large lettering with out a front sign could save you time and money Do your products have a special shape or color to emulate on your sign? Kodak is always in yellow and black, Coca-Cola white on red, Etc. Muffler places, have a sign in the shape of a muffler. your phone number on the store front some place, but not on the identification sign, (door, or window) Your Product & logos can be arranged on the front sign, or window. Not on the Pole sign, Store hours & phone number could fit in your design and by using the product color, it could add product recognition & enhance your design. Suppliers may provide plenty of advert...

Can Microsoft and Yahoo Co-Create New Businesses?

Negotiating The Future of Management Podcast Current Interactive Case Study Respectfully there's a parallel in modern history here. China-HongKong merger. It started as Two System One China. Controversial at that time. Now, many don't mind which system is better (respectfully just an opinion). Both are getting the best of each other under one country. Families are reunited regularly. Corporate identities sometimes focuses too much on what's different as a strategy. It may provide superiority, but does it always guarantee sustainability? Nature advocates the flourishing of various species; pursues diversity not for purposes of destruction but for better adaptability. Of the whole system. Being different doesn't mean one must separate oneself from the "whole" system. "Different" here is to provide a unique contribution to pserve the "whole". Task / role distribution , not identity separation. Preserving the whole system by b...

MP3 firmware upgrade --- switch

1: The most simple if the host machine using Sigma firmware and upgrade program is one! MP3 can be connected to the computer as long as the firmware installed on the computer, and then click on the face of that to upgrade the line of MP3! three antelope 7530 master points in several ways is to first get the firmware is sent to the machine within the sub-sub-folder off the machine DVR will automatically upgrade! Detailed steps have been described in general firmware! Shenzhen City Qing Wei Digital Appliance Co., Ltd.-KINGWAY http://www.kingwon.com.cn/ Technology Co., Ltd. Shenzhen, Pu-chih http://www.poozi.com/down.asp?le ...% D4% D8 & offset = 5 Section Crystal: http://www.fangke-model.com/ Chuanqi (ONKI): http://www.onki.cn/download.asp brother extremely grateful! CDT CDT http://xinvo.com/web/ ExcelStor MP3 http://www.hua-sun.com/xiazai.htm Bester http://www.szbaisite.com Beto www.beto.cn Butterfly www.it8.com.cn Acorp www.acorp.net.cn BES www.bes-chi...