八月 17, 2006

From:http://googlemapsbook.com/2006/08/10/parks-kml-explanation/

Yesterday, I demonstrated a KML file of Ontario Parks. Although this approach has some fairly serious limitations over a full mashup, the portability and ease of deployment make it an excellent choice in some situations.
In this article, I explain how the techniques used to generate the Ontario Parks KML. These are general-purpose tools that could certainly be harnessed to write a map_data file for the book’s Chapter 2 framework.

Developing the Parks KML

The Parks KML file has its origins with an actual mashup at the Ontario Parks website. That mashup reads from a data file (located here) that looks like the following:



...

We need a simple PHP script to grab this data, and generate KML. Each marker node from the original mashup needs to be translated into a KML Placemark, such as the following:


Awenda

http://ontarioparks.com/english/awen.html

-79.991000,44.784600

This conversion is simple enough that we could actually just implement it as an XML transformation, from one format to the next. However, as you could see from the demo, I actually did something slightly more with the Parks example, and that was to grab a blurb and facilities list for each park’s info bubble.

Spidering

To get the park descriptions, I was going to need to actually visit the page for each one. I knew it would take me a number of tries to get all the parsing working correctly, and I don’t want to hammer Ontario Parks, so I took the opportunity to put last week’s quickie session caching CURL class to work.

$url_index = 'http://ontarioparks.com/english/markers.xml';

require('../curl.php');
$curl = new CURL();
$curl->enableCache();

// fetch page, strip HTTP headers
$text_response = strstr($curl->get($url_index), '');
$xml = new SimpleXMLElement($text_response);

Having got the master list of parks in $xml, I could iterate through them with a foreach loop, and build up an array of data on the parks.

$url_base = 'http://www.ontarioparks.com/english/';
$marker_data = array();

foreach($xml->marker as $marker) {
$page = (string)$marker['url'];

// Some parks don't actually have a page.
if ('sorry.html' == $page) {
$desc = '(No data available about this park)‘;
} else {
$page_data = $curl->get($url_base . $page);
// extract info here; build $desc
}

$marker_data[] = array(
‘name’ => (string)$marker[’park’],
‘desc’ => $desc,
‘ll’ => (string)$marker[’lng’] . ‘,’ . (string)$marker[’lat’]
);
}

That first time running through all the 300+ parks was a pretty slow pageview, but after that, they all come from the session cache.—instantaneous *and* guilt-free!

Parsing

With a blob of page text for each park, the next task was to extract the description from it. Ontario Parks may be on the ball with their classy homepage and wordpress blog, but these old park pages are a markup disaster.

When iterating through rational XML, it makes sense to use tools such as SimpleXML and XPath. But when it’s a dog’s breakfast like this, some decisive regexes can end up being the easier approach. If we want to isolate the first description paragraph, for example, from Quetico, we can look at the surrounding markup for some good parsing hooks:


Image of Quetico

Quetico is a protected, pristine wilderness retreat of international acclaim west of Lake Superior on the Canada-U.S. border. The park’s tangled network of lakes once formed water routes travelled by Ojibway and fur traders. Now it is primarily the destination of experienced canoeists seeking solitude and rare glimpses of wildlife by cascading waterfalls, glassy lakes and endless forests. The park is accessible at four points by canoe and two by car (Dawson Trail Campground and Lac la Croix Ranger Station).
Bringing your own supply of firewood to the park this summer? Please read this.
 appears nowhere else but here, which makes it the best candidate we’ve got. This wouldn’t really be acceptable as a permanent solution, but we’re only running this once to generate our file, and we can tweak it as many times as it takes to get it right.
if (preg_match('#
.*?(.*?)

.*?

#is’, $page_data, $match)) {
$paragraph = trim(strip_tags($match[1]));
}

That regex may look scary as night, but the key part is that it grabs the first paragraph inside the specified td, and dot meta-character can include newlines. I only strip_tags it to get rid of the image, from those parks that have it.

Scraping out the activities and facilities is slightly more involved, but it’s the same principle at work, only in two stages. The first stage grabs the table surrounding them, and then a preg_match_all snatches each individual one. You can see it in action in the full code link at the bottom of the post. If there’s interest, I’ll put up a future article about regular expressions, specifically tailored to the art of scraping.

KML Output

Once I had everything in the big $marker_data array, it was just a matter of doing the actual generating KML part. You can see that I use short tags here, since it’s a template situation. You shouldn’t use them in portable code, but if it’s your own scripts, it can really turn up the readability and help distinguish PHP from markup.

'; ?>

Ontario Parks

]]>

It would have been possible to use SimpleXML or DOM to generate this XML, but it’s a fairly simple example

Saving To A File

When I was debugging all this, I’d let it simply output to the browser, where I could make a visual inspection. Once it came time to run it on Google Maps and Google Earth, I had it saved to a file for me, a task most easily accompished with output buffering:

 // start buffering

// do output ...

Once the file ends, the buffer gets written out to the screen anyways, but it’s also captured and saved to a file.

Limitations of KML

As stated yesterday, there are some fairly significant limitations on KML, particularly in the Google Maps implementation. The most glaring of these is the filesize limit, which could be overcome in part by just sending the points in batches and withholding infoWindow contents until specifically requested. Other points to consider:

  • You can’t use custom icons. There are 250 common ones that ship with Maps and Earth, which you can reference, although we didn’t bother in this case. This is a limitation that will hopefully be lifted in the near future, especially given that KML can already make external image references for overlays.
  • You can’t control everything. For example, the name field will become a tooltip in Earth, but it’s only a sidebar label in Maps. It is possible to do tooltips in a full mashup, of course, as demonstrated in Chapter 8 of the book, but the Maps implementation of KML doesn’t include this yet.
  • You can’t use JavaScript in the information bubbles, nor can you use the Google Maps tabbed infowindow. It would have been cool to also grab each park’s photograph, as well as the information about facilities and activities, but this data simply wouldn’t all fit in a single infowindow.

These limitations may be frustrating, but they’re hardly deal-breakers. For those dozens of mashups where you only need a few simple points plotted, why not just publish KML?

Full source here: Generate.php


八月 14, 2006

From:http://talk.163.com/06/0813/17/2OE0SJA800301IJI.html 

你会成为google地球的“猎物”吗?

【内容提要】:你玩过Google Earth了吗?如果你还没玩过,那可能有点落伍。如果你玩过,那你知道它有多少种玩法?有人说互联网改变着我们的生活维度,而Google Earth也许就是最好的证明。

在现实生活中,作为个人,你的家庭地址、人际往来,都有可能因为他人探秘隐私或商业上的需要,被敲进Google Earth的搜寻目录,成为它的猎物……

相关阅读:从Google卫星图“泄密”看中国专家愚昧与落后

娱乐篇:Google Earth的N种玩法

你玩过Google Earth了吗?如果你还没玩过,那可能有点落伍。如果你玩过,那你知道它有多少种玩法?有人说互联网改变着我们的生活维度,而Google Earth也许就是最好的证明。

■搜索范围:从床到厕所

2005年6月Google Earth的推出,让所有用户都体验到了那种震撼感觉,通过Google Earth,你可以浏览全球范围内任何一处地点的高清晰度卫星照片,甚至还可以从中找到自家屋顶。用户只要在地址搜寻栏里输入美国、加拿大、英国的街道 名,或者任何地方的经纬度数据,或者输入“白宫”“尼加拉瓜大瀑布”这样的词汇,所查找地方的卫星图像都能够迅速被放大,呈现在用户面前,而整个过程之流 畅,感觉就像身处好莱坞科幻电影的场景之中。

对于任何一个指定地点,Google Earth都可以显示出该区域的旅馆、饭店、博物馆甚至当地高尔夫课程的信息,只要你轻轻在这个神奇的数字地球上点击一下,所有这些信息就都在你的轻松掌 控之中,你可以对准备前往的度假胜地先进行一次虚拟游览,然后订购当地的高尔夫场地,或者看看当地饭店的菜单。最近,Google Earth又新添了一项服务,利用它你甚至可以在前往旅游目的地前就找到一张自己钟爱的床铺,并订好自己的早餐。

想想看,你甚至可以在还没有到达旅游目的时就了解了旅游点厕所的精确信息,当然还有自己满意的床的样子,把旅行规划到了如此方便的地步,不能不让人惊叹Google Earth的魅力。

如今前往澳大利亚旅行的游客再也不用为找不到厕所而发愁了,现在他们的旅行规划已经可以精确到厕所这一项。这全要归功于澳大利亚国家厕所地图站点www.toiletmap.gov.au最近利用Google Earth为用户提供的新服务。

现在你可以在Google Earth上找到全澳大利亚14295座公共厕所精确的经纬度以及卫星照片。有了如此精确的信息,旅行者估计再也不会为找不到厕所而烦恼了。而且使用者还 可以随时把这些地图信息下载到自己的手机和便携式GPS上,这样就可以随时就近找到方便之所。

■Google Earth上的淘宝族

正是由于Google Earth的强大魅力,成千上万的人开始沉迷其中,成了Google Earth上地地道道的淘宝一族。几乎每个星期,都会有GoogleEarth迷们声称又在GoogleEarth上发现了某个新的奇观。

比如有人在Google Earth上发现了一只熊,这迅速就成为Google Earth圈内的热门话题,还有人在纽约的三个房顶上发现了大胆的求爱告白,也有人以专门收集

Google Earth上发现的正在飞行的飞机图片为乐。这些Google Earth玩家们形成了各种稀奇古怪的兴趣小组,其增长速度之快、品种之多足以令人称奇。

最让这些Google Earth迷们津津乐道的一次寻宝经历也许算是古罗马庄园的发现了。一位意大利程序员在用Google Maps和Google Earth查看自己居住的Sorbolo小镇的卫星图片时,注意到一个500多米长的干涸河床,随后他又在附近发现了一个反常的长方形阴影,这位意大利程 序员立刻意识到这可能是一个古代人类的建筑遗迹,他甚至在阴影中找到类似于庭院形状的废墟。随即他将自己的发现张贴在了自己的博客日志上,并联系了当地的 考古学家。

考古学家们前往实地证实了他的发现,这片废墟散落着不少陶瓷碎片,是一个古罗马时期的庄园。同样,就在上个月,西班牙的业余天文学家埃米利奥冈萨雷斯利用GoogleEarth发现了乍得一个以前不为人知的撞击坑。

■玩转2006年世界杯

高科技大众化所带来的变化总会让人惊奇。2006年世界杯将于6月在德国举行,全世界的球迷 早已为此兴奋不已,他们找到了一个发泄自己热情的新途径,这就是Google Earth。在Google Earth社区论坛里,来自全世界的球迷不断识别着Goog leEarth上分布在全球各处足球场的卫星图像。

截至4月21日,已经有超过4783个足球场被这些兴奋的足球迷们识别了出来,而且这个数字还在不断上升。每个被识别出的足球场,都被球迷进行了仔细标注,并附上该体育馆的链接和基本信息。现在,这已经成为了Google Earth上最受欢迎的网上观景项目。

一位网友曾在Google Earth论坛里发帖说,如果德国世界杯开始时,只要打开Google Earth,点一下德国的球场,就能看比赛就好了。这听上去有点异想天开,然而这在不久的将来很可能会变为现实。

事实上,Google与美国探索频道Discovery已经决定联手提供全球著名历史遗迹的 视频片断。在接下来的几周内,在Google Earth上的一些著名历史遗迹上将出现特殊球形图标。只要点击这个图标,就可链接到Discovery的服务器,随即就可以观看到有关这个遗迹的视频录 像。据悉,最先上线的将是美国的10个国家公园,稍后全球的文化名胜会陆续上线。

对于Google Earth的这种热情并不仅限于足球迷,4月初,美国“星期四乐队”首次利用Google Earth提供的服务,发动全球乐迷一同参与一场网上网下的寻宝游戏。乐迷可以循着Google Earth上的线索一点一点找出该乐队在全球巡演的所有地点。5月4日,乐队将现场公布获胜者。

与“星期四乐队”类似,美国著名的计算机站点CNET也借着Google Earth的火爆举办了一场配对游戏。参赛者被要求根据所给出的Google Earth上10个全球知名科技公司的卫星图片找出每张图片中的建筑对应的是哪家公司,这些知名科技公司包括Ama-zon.com、苹果电脑、思科公 司、戴尔等等,当然也包括Google自己。这个游戏一经推出就吸引了众多参赛者,CNET的点击率也因此不断攀升。

商业篇:效应非凡

最初Google Earth起步时,很多人都把它看作是面对普通消费者的酷玩意,然而现在很多企业却发现Google Earth具有巨大的商业价值。

2006年3月初,一位以Google Earth寻宝为乐的玩家发现了一个秘密,在澳大利亚西部发现了苹果公司iPod的超大广告。这个超巨大的iPod,占地面积约893000平方米,约80个美式足球场那么大。

原来是在两年前,史蒂夫乔伯斯在与澳洲出版业大亨克里派克玩一场扑克游戏时,赢到了一个面积超大的矿场。此后,这块地就一直在秘密地进行着改装,后来在这块地上布置了一幅巨大的iPod广告。苹果的这一举动无意间开创了在Google Earth上做广告的先河。

“Google Earth真的是无处不在”。这是美国著名的工程软件公司本特利系统公司全球市场负责人乔克罗瑟在接受美国《信息周刊》采访时发出的感叹。

现在很多行业都在利用Google Earth。不久前,本特利系统公司在其设计软件中加入了可以在Google Earth上直接发布建筑工程2D与3D模型的功能。该公司认为,这将让建筑模型看起来更为真实。该公司首席执行官说:“它是无所不在的,至少在我们这个 行业是如此。”

事实上,Google Earth的应用早已超出了建筑工程领域。由于它可以结合GPS与无线电射频识别系统,因此可以被用于资产管理。

戴尔公司就利用Google Earth跟踪客户在亚洲的库存情况,并把它作为其产品库存管理系统的一部分;日本的本田公司则在最近为日本市场上的思域轿车提供Google Earth卫星地图导航服务;据称大众汽车也在和NVIDIA合作开发类似的系统。而在旅游领域,最近挪威第二大城市贝尔根主动与Google合作,提出 为Google Earth提供清晰度达到15分米的图像,目的只有一个,就是旅游推广。

从建筑业、旅游业再到广告业,都可以看到“Google Earth”的身影,而当大家还没来得及好好消化掉“Google Earth”所带来的震撼之时,Google又推出了“Google Moon(Google月球)”。而不久前,“Google Mars(Google火星)”又悄然登场。

2006年4月11日,美国的《商业周刊》刊登了《Google组织整个地球》的文章,在这篇文章中作者剖析了Google不断取得商业成功背后的原因。

文章写道:“在过去的8年中,Google一直在以一种非同寻常的方式进化……很多 评论家不理解Google品牌的DNA密码,这是因为它与我们在目前市场领域所看到的任何企业的增长模式都不同。Google也许是第一家完全基于干细胞 模式构建的企业,它能够不断成长与发展为任何适合的形态。”

在Google的企业宣言中有这样一句话,“整合全球信息,让其在全球范围内都可以很容易地获取和使用”。

在这一雄心勃勃目标的背后,是巨大的商业利益。通过为用户免费提供高清晰度的卫星图像服务, 带来印象深刻的震撼体验,Google Earth已经迅速将全球信息整合这个概念暗暗植入用户心中,在将来全球任一个地点的状况以及最新资讯,你都有可能从Google Earth的虚拟现实场景中搜集到,到那个时候,Google也许真正将成为虚拟帝国之王。